• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 406
  • Last Modified:

How to draw lines or rectangle in my WInForm ?

    Hi experts!

  Im using C# 2008 , WinForm NET 2. Probably is stupid question, but I needed to know how to draw line or rectangle or circle in my WinForm. This object need to be static and if is possible to be visible in design view of form.
Probably best is to draw them as control, but I can not find such controls in Toolbox ?
Do I need third part components for this ?
 I cannot use Group Bar because I have controls in loop of the forms.
0
dvplayltd
Asked:
dvplayltd
  • 2
  • 2
1 Solution
 
käµfm³d 👽Commented:
You create a graphics object from the form and use that to draw with:
untitled.JPG
0
 
dvplayltdAuthor Commented:
To kaufmed

Thank you, but not help for my purpose, it will be too slow.
I have other object and want when move this object to move and line. With this - yes it will work but will take many time to set exatly position.
0
 
käµfm³d 👽Commented:
I'm not sure I understand what you mean by "it will be too slow." What will cause the following to take "too much" time, as you understand it?
public partial class Form1 : Form
{
    Graphics g;
 
    public Form1()
    {
        InitializeComponent();
        g = this.CreateGraphics();
    }
 
    private void button1_Click(object sender, EventArgs e)
    {
        g.Clear(this.BackColor);
        this.button1.Top = this.button1.Top - 10;            
    }
 
    protected override void OnPaint(PaintEventArgs e)
    {
        base.OnPaint(e);
        int bottomPos = this.button1.Top + this.button1.Height;
 
        g.DrawLine(Pens.Black, new Point(this.button1.Left, bottomPos + 5), new Point(this.button1.Left + this.button1.Width, bottomPos + 5));            
    }
}

Open in new window

0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
"...and if is possible to be visible in design view of form."

You can use the Visual Basic Power Packs provided by Microsoft:
http://www.microsoft.com/downloads/details.aspx?FamilyId=371368A8-7FDC-441F-8E7D-FE78D96D4063&displaylang=en

See Emoreua's article here:
http://www.emoreau.com/Entries/Articles/2008/03/Microsoft-Visual-Basic-Power-Packs-30.aspx

And yes, you can use the pack in C#...
0
 
dvplayltdAuthor Commented:
Very good , thank you !
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now