Browse Source

added spinner control to widgets library

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@1987 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Markus Palme 19 years ago
parent
commit
6b7b965d82
  1. 1
      src/Main/ICSharpCode.SharpDevelop.Widgets/Project/ICSharpCode.SharpDevelop.Widgets.csproj
  2. 92
      src/Main/ICSharpCode.SharpDevelop.Widgets/Project/SpinnerControl.cs

1
src/Main/ICSharpCode.SharpDevelop.Widgets/Project/ICSharpCode.SharpDevelop.Widgets.csproj

@ -63,6 +63,7 @@ @@ -63,6 +63,7 @@
<Compile Include="SideBar\SideBar.cs" />
<Compile Include="SideBar\SideTab.cs" />
<Compile Include="SideBar\SideTabItem.cs" />
<Compile Include="SpinnerControl.cs" />
</ItemGroup>
<ItemGroup>
<Folder Include="Configuration" />

92
src/Main/ICSharpCode.SharpDevelop.Widgets/Project/SpinnerControl.cs

@ -0,0 +1,92 @@ @@ -0,0 +1,92 @@
using System;
using System.Windows.Forms;
using System.Drawing;
namespace ICSharpCode.SharpDevelop.Widgets
{
public class SpinnerControl : UserControl
{
private int lines = 8;
private int current = 0;
private Timer timer;
public SpinnerControl()
{
SetStyle(ControlStyles.UserPaint, true);
SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
}
public int Lines
{
get
{
return lines;
}
set
{
this.lines = value;
}
}
public void Start()
{
timer = new Timer();
timer.Interval = 100;
timer.Tick += new EventHandler(timer_Tick);
timer.Start();
}
void timer_Tick(object sender, EventArgs e)
{
if (this.current >= this.lines - 1)
{
this.current = 0;
}
else
{
this.current++;
}
Invalidate();
}
public void Stop ()
{
timer.Stop();
}
protected override void OnPaint(PaintEventArgs e)
{
double x, y;
double radius;
double half;
int i;
x = Width / 2;
y = Height / 2;
radius = Math.Min(Width / 2, Height / 2) - 5;
half = lines / 2;
for (i = 0; i < lines; i++)
{
double inset = 0.7 * radius;
double t = (double)((i + lines - current) % lines) / lines;
Color c = Color.FromArgb((int)(t * 255), 0, 0, 0);
Pen pen = new Pen(c);
pen.Width = 2;
PointF start = new PointF((float)(x + (radius - inset) * Math.Cos(i * Math.PI / half)),
(float)(y + (radius - inset) * Math.Sin(i * Math.PI / half)));
PointF end = new PointF((float)(x + radius * Math.Cos(i * Math.PI / half)),
(float)(y + radius * Math.Sin(i * Math.PI / half)));
e.Graphics.DrawLine(pen, start, end);
pen.Dispose();
}
base.OnPaint(e);
}
}
}
Loading…
Cancel
Save