使用图纸启动面板
本文关键字:启动 | 更新日期: 2023-09-27 18:27:36
我现在在面板上画一些点,表示一种点网格,其边距为面板总宽度的1%。
这就是我现在正在做的:
private void panel1_Paint(object sender, PaintEventArgs e)
{
Pen my_pen = new Pen(Color.Gray);
int x,y;
int k = 1 ,t = 1;
int onePercentWidth = panel1.Width / 100;
for (y = onePercentWidth; y < panel1.Height-1; y += onePercentWidth)
{
for (x = onePercentWidth; x < panel1.Width-1; x += onePercentWidth)
{
e.Graphics.DrawEllipse(my_pen, x, y, 1, 1);
}
}
}
困扰我的是,当应用程序启动时,我可以看到面板上画的点。即使它很快,它仍然让我很困扰。
可以在面板上画点并直接加载吗?
感谢您的帮助
您可以创建一个位图并绘制它。
但在此之前:DrawEllipse
有点贵。将DrawLine
与具有虚线样式的Pen
一起使用:
int onePercentWidth = panel1.ClientSize.Width / 100;
using (Pen my_pen = new Pen(Color.Gray, 1f))
{
my_pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Custom;
my_pen.DashPattern = new float[] { 1F, onePercentWidth -1 };
for (int y = onePercentWidth; y < panel1.ClientSize.Height - 1; y += onePercentWidth)
e.Graphics.DrawLine(my_pen, 0, y, panel1.ClientSize.Width, y);
}
注意,我使用的是using
,所以我不会泄露Pen
和ClientSize
,所以我只使用内部宽度。还要注意MSDN 上关于自定义DashPattern
的详细说明