EDIT: I said drawing line and the code tries to draw rectangle I know. I can change that when I can drive the rectangle. That's not the problem.
I can't draw a line. I checked out documents but I just can't do it.
I want to declare a class that inherited from Form
, and I declared a constructor there which will draw the rectangle. Then in main, I am calling it, but it doesn't work.
namespace game
{
public class Screen : Form
{
public Screen()
{
Graphics g = CreateGraphics();
var rectangle = new System.Drawing.Rectangle(100, 100, 200, 200);
g.DrawRectangle(System.Drawing.Pens.Black, rectangle);
}
}
class Program
{
static void Main()
{
Application.Run(new Screen());
}
}
}
edit2: g = this.CreateGraphics(); doesn't work,
in this one,
private void Form1_Paint(object sender,
System.Windows.Forms.PaintEventArgs pe)
{
// Declares the Graphics object and sets it to the Graphics object
// supplied in the PaintEventArgs.
Graphics g = pe.Graphics;
// Insert code to paint the form here.
}
i don't see how i can give the arguments to call it