How to draw lines or rectangle in my WInForm ?

Posted on 2009-04-23
Last Modified: 2013-12-17
    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.
Question by:dvplayltd
    LVL 74

    Expert Comment

    by:käµfm³d 👽
    You create a graphics object from the form and use that to draw with:

    Author Comment

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

    Expert Comment

    by:käµfm³d 👽
    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()
            g = this.CreateGraphics();
        private void button1_Click(object sender, EventArgs e)
            this.button1.Top = this.button1.Top - 10;            
        protected override void OnPaint(PaintEventArgs 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

    LVL 85

    Accepted Solution

    "...and if is possible to be visible in design view of form."

    You can use the Visual Basic Power Packs provided by Microsoft:

    See Emoreua's article here:

    And yes, you can use the pack in C#...

    Author Closing Comment

    Very good , thank you !

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Normally a window is moved by clicking on the caption bar and dragging. You may want your user to be able to move borderless forms or move a form by clicking anywhere in the form without the limitation to the caption bar. There are many ways to do i…
    More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now