Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/264.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用图纸启动面板_C# - Fatal编程技术网

C# 使用图纸启动面板

C# 使用图纸启动面板,c#,C#,我现在在一个面板上画一些点,表示一种虚线网格,占面板总宽度的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;

我现在在一个面板上画一些点,表示一种虚线网格,占面板总宽度的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);
            }
        }
    }
private void panel 1_Paint(对象发送器,PaintEventArgs e)
{
钢笔我的钢笔=新钢笔(颜色为灰色);
int x,y;
int k=1,t=1;
int onePercentWidth=panel1.宽度/100;
对于(y=百分之一宽度;y
困扰我的是,当应用程序启动时,我可以看到面板上画的点。即使它很快,它仍然困扰着我很多

是否可以在面板上绘制点并直接加载绘制的点


感谢您的帮助

您可以创建位图并绘制它

但在此之前:
drawerlipse
有点贵。使用带有虚线样式的
笔使用
抽绳

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);
}
int onePercentWidth=panel1.ClientSize.Width/100;
使用(我的钢笔=新钢笔(颜色:灰色,1f))
{
my_pen.DashStyle=System.Drawing.Drawing2D.DashStyle.Custom;
my_pen.DashPattern=新浮点[]{1F,onePercentWidth-1};
对于(int y=onePercentWidth;y

请注意,我使用的是
using
,因此我不会泄漏
客户端大小
,因此我只使用内部宽度。还要注意关于自定义
DashPattern

的检查,好的,我现在意识到我在抱怨我糟糕的编程造成的问题。谢谢你的帮助。。它的工作原理完全符合我的要求,尽管我认为我仍然需要理解它是如何在整个面板上绘制的,而不仅仅是在一条线上绘制的。我将检查clientsize和using以理解。请查看微小的更正(
onePercentWidth-1};
)。-它在整个面板上画了许多线,每一条线都有一个虚线样式,完全符合线的间距。(我在for循环后保存了一对大括号;这不是推荐的编码风格。)但是,是的,绘图有很多技巧、陷阱和奇迹。。祝你学习愉快!