Drawing a line in Winforms

后端 未结 5 731
无人及你
无人及你 2020-12-19 07:36

I am having trouble drawing a line within a group box in a simple windows form.

here is my code:

public partial class Form1 : Form
    {
        publ         


        
5条回答
  •  天涯浪人
    2020-12-19 08:26

    Hook up an event handler for the Paint event of the GroupBox and call DrawLShapeLine from within that event handler instead. You should then use the Graphics object supplied by in event arguments:

    private void groupBox1_Paint(object sender, PaintEventArgs e)
    {
        DrawLShapeLine(e.Graphics, 10, 10, 20, 40);
    }
    

    As your code looks now it will attempt to paint in the GroupBox when the form requires painting. The group box may be painted at any other occasion, which will the line you paint disappear.

提交回复
热议问题