Link to home
Start Free TrialLog in
Avatar of dvplayltd
dvplayltdFlag for Bulgaria

asked on

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.
Avatar of kaufmed
kaufmed
Flag of United States of America image

You create a graphics object from the form and use that to draw with:
untitled.JPG
Avatar of dvplayltd

ASKER

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.
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

ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Very good , thank you !