Skip to content

How to create a rectangle in a form in C#

Poornima Venkataraman

Asked Dec 7, 2006, 7:43 PM EST1 answer
Share
LinkedInX
Hello
My requirement is to create an editor for electronic drives where i have a matrix of 120/8.

I need to create rectangles for that.I wrote the following code,to create a rectangle but in o/p form nothing is to be seen.My code is

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

namespace ZelioLadderEditor

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}

public void RectangleInflateTest(PaintEventArgs e)

{

// Create a rectangle.

Rectangle rect = new Rectangle();

rect.X = 800;

rect.Y = 100;

rect.Width = 250;

rect.Height = 200;

Can any one of you tell me what is the error

Thanks In Advance
Poornima

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    Java
    public void RectangleInflateTest(PaintEventArgs e)
    {
    Rectangle rect = new Rectangle();
    rect.X = 40;
    rect.Y = 40;
    rect.Width = 150;
    rect.Height = 200;
    
    // Create a new pen.
    Pen blackPen = new Pen(Brushes.Black);
    // Set the pen's width.
    //blackPen.Width = 1.0F;
    // Draw a rectangle.
    e.Graphics.DrawRectangle(blackPen, rect);
    //Dispose of the pen.
    blackPen.Dispose();
    
    
    
    }
    0