【发布时间】:2015-07-01 13:53:34
【问题描述】:
我正在尝试编写一个简单的应用程序,它以一定的速度打印一条“移动”的线,这是我第一次使用 c# 和 Windows 创建应用程序,我找到了一个帮助我画线的教程,到目前为止我明白了:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.InteropServices;
using System.Drawing;
using System.Threading;
using System.Windows.Forms;
namespace ConsoleApplication1
{
class Program
{
[DllImport("User32.dll")]
static extern IntPtr GetDC(IntPtr hwnd);
static void draw(Rectangle r, Brush b, IntPtr hwnd)
{
using(Graphics g = Graphics.FromHdc(hwnd))
{
g.FillRectangle(b, r);
}
}
static void Main(string[] args)
{
int x = 0;
while (true)
{
draw(new Rectangle(x, 0, 50, 1080), Brushes.PaleGoldenrod, GetDC(IntPtr.Zero));
x++;
}
}
}
}
问题是我不知道如何擦除前一行,或者在画完一条线后刷新屏幕。
欢迎任何帮助。
谢谢!
【问题讨论】:
-
简短的回答,用那种“绘图”的方法,你不会。这些线条会被你在上面画的任何东西抹去。那可能是桌面本身,或其他应用程序窗口。当他们重新绘制自己时,这些线条将被删除。
-
感谢您的回答,您知道我可以使用什么方法来实现此目的吗?谢谢!
-
第一步:扔掉教程,清理链接!阅读 Paint 事件和 Timer Tick
标签: c# windows screen line draw