Drawing a line in Winforms

后端 未结 5 715
无人及你
无人及你 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:11

    Another option would be to use the line control that is available in Visual Basic Power Packs.

    http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/d9e082c8-5386-4481-a744-1c9029805696/

    If you have Visual Studio 2008 SP1, or Visual Studio 2010, you won't need to download anything.

    If you do not see the Visual Basic PowerPacks control in the Toolbox, right click in the Toolbox and select Show All in the context menu.

    0 讨论(0)
  • 2020-12-19 08:22

    Add a label with no text, a 3D border and a height of 2 (you have to set the height in the properties page, not with the GUI)!

    0 讨论(0)
  • 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.

    0 讨论(0)
  • 2020-12-19 08:27

    I'm not sure if something else is going on, but you should draw the line on the GroupBox's Paint event, not the Form's.

    0 讨论(0)
  • Quick & dirty:

    How about creating a panel with the width of 1 pixel and give it a backgroundcolor?

    0 讨论(0)
提交回复
热议问题