我在桌面上绘制线条并想要删除旧的线条以使线条轮换? [英] I draw lines on the desktop and want to remove the old ones to make a rotation look in lines?

查看:79
本文介绍了我在桌面上绘制线条并想要删除旧的线条以使线条轮换?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在屏幕的左上方进行快速移动的线条运动(以保持警惕),我设法绘制线条,但我想删除前一个(或者如果运动更平滑的那些),如何隐藏桌面上的前一行或其上的任何内容(刷新屏幕的这一部分可能有所帮助)。



我尝试过:



 [DllImport(User32.dll)] 
public static extern IntPtr GetDC(IntPtr hwnd);
[DllImport(User32.dll)]
public static extern void ReleaseDC(IntPtr hwnd,IntPtr dc);
//获取整个屏幕的Graphics对象并用它绘制一个矩形:

int currentLine = 0,totalNumOfLines = 12;

点数=新点(60,60);

private void FormSettings_Load(object sender,EventArgs e)
{
desktopPtr = GetDC(IntPtr.Zero);
g = Graphics.FromHdc(desktopPtr);
}

IntPtr desktopPtr;

图形g;

private void FormSettings_FormClosed(object sender,FormClosedEventArgs e)
{
g.Dispose();
ReleaseDC(IntPtr.Zero,desktopPtr);
}

private void timerDraw_Tick(object sender,EventArgs e)
{
g.Dispose();
ReleaseDC(IntPtr.Zero,desktopPtr);

desktopPtr = GetDC(IntPtr.Zero);
g = Graphics.FromHdc(desktopPtr);

currentLine ++;

if(currentLine == totalNumOfLines)currentLine = 0;

g.DrawLine(新笔(Color.Yellow,2),point.X,point.Y
,point.X +(int)(50 * Math.Cos((currentLine) /(double)totalNumOfLines)* Math.PI * 2))
,point.Y +(int)(50 * Math.Sin((currentLine /(double)totalNumOfLines)* Math.PI * 2))) ;
}

解决方案

如果您的代码正在绘制线条,您必须不断更新位置线条的端点并使用这些新值重新绘制线条。



实际上没有擦除这些线条的东西。您必须在绘制线条的位置绘制区域,然后在它们上面绘制新线条。您的外观看起来像这样,假设一条线并在一个小盒子中绘图,比如20 x 20像素:

初始化线端点值,比如说0,0和20,20。 />
抓住你要画线的20x20盒子的快照。

启动你的计时器以触发绘制下一个帧。



定时器循环:

绘制你带回原始位置的快照以擦除任何一行。

画出你的线。 br />
更新下一帧行终点的位置。

完成 - 在下一个定时器tick上,你的代码重新开始定时器循环。 / BLOCKQUOTE>

I want to make fast moving lines motion on the top left of the screen (to keep myself alert), I managed to draw the lines, but I want to remove the previous one (or ones if a smoother motion), how to hide the previous lines from the desktop or whatever is on it (refreshing this part of the screen may help).

What I have tried:

[DllImport("User32.dll")]
public static extern IntPtr GetDC(IntPtr hwnd);
[DllImport("User32.dll")]
public static extern void ReleaseDC(IntPtr hwnd, IntPtr dc);
//Get a Graphics object for the entire screen and draw a rectangle with it:

int currentLine = 0, totalNumOfLines=12;

Point point = new Point(60, 60);

private void FormSettings_Load(object sender, EventArgs e)
{
    desktopPtr = GetDC(IntPtr.Zero);
    g = Graphics.FromHdc(desktopPtr);
}

IntPtr desktopPtr;

Graphics g;

private void FormSettings_FormClosed(object sender, FormClosedEventArgs e)
{
    g.Dispose();
    ReleaseDC(IntPtr.Zero, desktopPtr);
}

private void timerDraw_Tick(object sender, EventArgs e)
{
    g.Dispose();
    ReleaseDC(IntPtr.Zero, desktopPtr);

    desktopPtr = GetDC(IntPtr.Zero);
    g = Graphics.FromHdc(desktopPtr);

    currentLine++;

    if (currentLine == totalNumOfLines) currentLine = 0;

    g.DrawLine(new Pen(Color.Yellow, 2), point.X, point.Y
        , point.X + (int)(50 * Math.Cos((currentLine / (double)totalNumOfLines) * Math.PI * 2))
        , point.Y + (int)(50 * Math.Sin((currentLine / (double)totalNumOfLines) * Math.PI * 2)));
}

解决方案

If your code is drawing the lines, you have to constantly update the positions of the endpoints of the lines and redraw the lines using these new values.

There is really no such thing as "erasing" those lines. You have to draw the area under where you drew your lines and then draw your new lines on top of them. Your look would look something like this, assuming a single line and drawing in a small box, say 20 x 20 pixels:
Initialize your line endpoint values, say 0,0 and 20,20.
Grab a snapshot of the 20x20 box you're going to draw your line in.
Start your timer to trigger drawing the next "frame".

Timer loop:
Draw the snapshot you took back to the original position to "erase" any line.
Draw your line.
Update the positions of the line endpoints for the next frame.
Done - on the next timer "tick", your code start the "timer loop" all over again.


这篇关于我在桌面上绘制线条并想要删除旧的线条以使线条轮换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆