How do I draw circles, rectangles, lines and text

Platform: WinForms| Category: Drawing Tips

Handle the Paint event for your control or form.

  private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
  {
    Graphics g = e.Graphics;
    Pen pen = new Pen(Color.White, 2);
    SolidBrush redBrush = new SolidBrush(Color.Red);

    g.DrawEllipse(pen, 100,150,100,100);
    g.DrawString('Circle', this.Font, redBrush, 80, 150);

    g.FillRectangle(redBrush, 140, 35, 20, 40);
    g.DrawString('Rectangle', this.Font, redBrush, 80, 50);

    g.DrawLine(pen, 114, 110, 150, 110);
    g.DrawString('Line', this.Font, redBrush, 80, 104);
  }

Share with

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.