Little test for invalidation. Nice for profiling.
svn path=/trunk/winforms/; revision=54257
This commit is contained in:
Родитель
91c73ffd9f
Коммит
e366382ede
|
@ -0,0 +1,10 @@
|
|||
all: mono
|
||||
|
||||
mono: swf-invalidate.cs
|
||||
mcs swf-invalidate.cs /r:System.Windows.Forms.dll /r:System.Drawing.dll
|
||||
|
||||
dotnet: swf-invalidate.cs
|
||||
csc swf-invalidate.cs /r:System.Windows.Forms.dll /r:System.Drawing.dll
|
||||
|
||||
clean:
|
||||
rm swf-invalidate.exe -r -f
|
|
@ -0,0 +1,70 @@
|
|||
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
|
||||
|
||||
|
||||
public class InvalidateForm : Form {
|
||||
|
||||
private Timer timer;
|
||||
private int width;
|
||||
private bool region;
|
||||
|
||||
public InvalidateForm ()
|
||||
{
|
||||
timer = new Timer ();
|
||||
timer.Interval = 500;
|
||||
timer.Tick += new EventHandler (TimerTick);
|
||||
timer.Enabled = true;
|
||||
|
||||
BackColor = Color.Blue;
|
||||
|
||||
Paint += new PaintEventHandler (PaintHandler);
|
||||
Click += new EventHandler (ClickHandler);
|
||||
}
|
||||
|
||||
private void TimerTick (object sender, EventArgs e)
|
||||
{
|
||||
width += 10;
|
||||
if (width > Width + 11) {
|
||||
width = 0;
|
||||
Refresh ();
|
||||
region = !region;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!region) {
|
||||
Invalidate (new Rectangle (0, 0, width, Height));
|
||||
} else {
|
||||
int half = width / 2;
|
||||
int xmiddle = Width / 2;
|
||||
int ymiddle = Height / 2;
|
||||
Rectangle rect = new Rectangle (xmiddle - half, ymiddle - half, width, width);
|
||||
Invalidate (new Region (rect));
|
||||
}
|
||||
}
|
||||
|
||||
private void ClickHandler (object sender, EventArgs e)
|
||||
{
|
||||
timer.Enabled = !timer.Enabled;
|
||||
}
|
||||
|
||||
private void PaintHandler (object sender, PaintEventArgs pe)
|
||||
{
|
||||
if (pe.ClipRectangle.Width == Width && pe.ClipRectangle.Height == Height) {
|
||||
Console.WriteLine ("Clearing Form");
|
||||
pe.Graphics.FillRectangle (new SolidBrush (BackColor), pe.ClipRectangle);
|
||||
return;
|
||||
}
|
||||
|
||||
Console.WriteLine ("Filling: " + pe.ClipRectangle);
|
||||
pe.Graphics.FillRectangle (new SolidBrush (Color.Red), pe.ClipRectangle);
|
||||
}
|
||||
|
||||
public static void Main ()
|
||||
{
|
||||
Application.Run (new InvalidateForm ());
|
||||
}
|
||||
}
|
||||
|
Загрузка…
Ссылка в новой задаче