简体   繁体   English

在C#表单上绘制的线太长

[英]Line Drawn On C# Form Too Long

I haven't seen any posts relating to this but a line drawn on my form is supposed to stop 5px before the boarder around the form but it doesn't. 我还没有看到与此相关的任何帖子,但是在表单上绘制的线条应该在表单寄宿生之前停靠5px,但事实并非如此。 The purpose of this line is to separate two different user controls on one form if need be. 该行的目的是根据需要在一个表单上分离两个不同的用户控件。

    protected override void OnPaint(PaintEventArgs e)
    {
        base.OnPaint(e);
        if (optionalSecondPanel != null)
        {
            Graphics g;

            g = e.Graphics;

            Pen myPen = new System.Drawing.Pen(System.Drawing.Color.Black);
            g.DrawLine(myPen, mainPanel.Width + 5, btnPannel.Bottom + 5, mainPanel.Width + 5, this.Height - 5);
            myPen.Dispose();
            g.Dispose();
        }
    }

However when drawn on the screen the line separating the user controls goes all the way to the bottom of the form. 但是,当在屏幕上绘制时,用户控件之间的分隔线会一直到达表单底部。 It doesn't stop when it is supposed to. 它不应该停止在应该的时候。

g.DrawLine(myPen, mainPanel.Width + 5, btnPannel.Bottom - 5, mainPanel.Width + 5, this.Height - 5);

我相信.Bottom增加会下降,因此,如果减去5,它应该会增加该条的底部。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM