delegate void lineddaproc(int x, int y, intptr lpdata);
[dllimport("gdi32.dll")]
static extern int linedda(int nxstart, int nystart, int nxend, int nyend,
lineddaproc lplinefunc, intptr lpdata);
private const byte pt_closefigure = 1;
private const byte pt_lineto = 2;
private const byte pt_bezierto = 4;
private const byte pt_moveto = 6;
[dllimport("gdi32.dll")]
static extern int setpixel(intptr hdc, int x, int y, int crcolor);
graphicspath graphicspath = new graphicspath();
private int counter = 0;
private intptr graphicshandle = intptr.zero;
//设计zswang 2007-04-30 wjhu111#21cn.com 尊重作者,转贴请注明出处
private void button1_click(object sender, eventargs e)
{
graphicspath.clearmarkers();
graphicspath.addrectangle(new rectangle(10, 10, 100, 100));
timer1.interval = 100;
timer1.enabled = true;
}
private void movingdots(int x, int y, intptr lpdata)
{
counter = (counter + 1) % 15;
color vcolor;
if (counter < 5)
vcolor = color.white;
else if (counter < 12)
vcolor = color.red;
else vcolor = color.blue;
setpixel(graphicshandle, x, y, vcolor.r | vcolor.g << 8 | vcolor.b << 16);
}
private void timer1_tick(object sender, eventargs e)
{
graphicshandle = graphics.fromhwnd(handle).gethdc();
for (int i = 0; i < graphicspath.pathpoints.length; i++)
{
if (graphicspath.pathtypes[i] == (byte)(pt_closefigure | pt_lineto))
{
for (int j = i; j >= 0; j--)
{
if (graphicspath.pathtypes[j] == pt_moveto)
{
linedda(
(int)graphicspath.pathpoints[i].x,
(int)graphicspath.pathpoints[i].y,
(int)graphicspath.pathpoints[j].x,
(int)graphicspath.pathpoints[j].y,
movingdots, intptr.zero);
break;
}
}
continue;
}
if (i == graphicspath.pathpoints.length - 1)
linedda(
(int)graphicspath.pathpoints[i].x,
(int)graphicspath.pathpoints[i].y,
(int)graphicspath.pathpoints[0].x,
(int)graphicspath.pathpoints[0].y,
movingdots, intptr.zero);
else
linedda(
(int)graphicspath.pathpoints[i].x,
(int)graphicspath.pathpoints[i].y,
(int)graphicspath.pathpoints[i + 1].x,
(int)graphicspath.pathpoints[i + 1].y,
movingdots, intptr.zero);
}
}
新闻热点
疑难解答