public partial class Form1 : Form{
[DllImport("Gdi32.dll ")]
public static extern int SetPixel(IntPtr hDC, int x, int y, int color);
public Form1(){
InitializeComponent();
}
protected override void OnPaint(PaintEventArgs e) {
base.OnPaint(e);
IntPtr hdc = e.Graphics.GetHdc();
for (int i = 0; i < 100; i++) {
SetPixel(hdc, 20, 20 + i, 0);
}
}
}
显示效果

本文展示了一个使用C#和GDI+进行简单绘图的例子。通过调用SetPixel函数,该示例在窗体上绘制了一条由100个像素组成的垂直线条。这个例子适合初学者理解如何在Windows窗体中进行基本的绘图操作。
1756

被折叠的 条评论
为什么被折叠?



