Click here to Skip to main content
15,886,689 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
What should i write to inicialize a program to draw shapes and lines on the screen ?

I have tried some code, but it fails. Not working ...

(for while, i just can code to make simple things as console input and output/Console.ReadLine, Console.WriteLine ...)

Thank you/Regards
Carlos

What I have tried:

C#
public void DrawRectangleRectangle(PaintEventArgs e)
{

    // Create pen.
    Pen blackPen = new Pen(Color.Black, 3);

    // Create rectangle.
    Rectangle rect = new Rectangle(0, 0, 200, 200);

    // Draw rectangle to screen.
    e.Graphics.DrawRectangle(blackPen, rect);
}
Posted
Updated 14-Dec-17 1:41am
v2

1 solution

Such code works, actually.
Create an empty Windows Form project, add the on paint event handler and modify it this way:
C#
private void Form1_Paint(object sender, PaintEventArgs e)
{
  DrawRectangleRectangle(e);
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900