PublicForm1 () {InitializeComponent (); } Private voidButton1_Click (Objectsender, EventArgs e) {Graphics g= This. CreateGraphics ();//creating GDI pairs like//Create a brush (color)Pen Npen =NewPen (brushes.red); //Create two pointsPoint N1 =NewPoint ( -, -); Point N2=NewPoint (255,255); G.drawline (Npen, N1, N2); } Private voidForm1_paint (Objectsender, PaintEventArgs e) {Graphics g= This. CreateGraphics ();//creating GDI pairs like//Create a brush (color)Pen Npen =NewPen (brushes.red); //Create two pointsPoint N1 =NewPoint ( -, -); Point N2=NewPoint (255,255); G.drawline (Npen, N1, N2); } Private voidButton2_Click (Objectsender, EventArgs e) {Graphics ng= This. CreateGraphics (); //Create a brushPen Npen =NewPen (brushes.red); Size sz=NewSystem.Drawing.Size ( -, -); Rectangle Res=NewRectangle (NewPoint ( -, -), SZ); Ng. DrawRectangle (Npen, RES); } Private voidButton3_Click (Objectsender, EventArgs e) {Graphics g= This. CreateGraphics (); Pen Npen=NewPen (Brushes.blue); Size sz=NewSystem.Drawing.Size ( the, the); Rectangle Rec=NewRectangle (NewPoint ( Max, Max), SZ); G.drawpie (Npen, REC,- -, - -); } Private voidButton4_Click (Objectsender, EventArgs e) {Graphics g= This. CreateGraphics (); Pen Npen=NewPen (Brushes.blue); g.DrawString ("I am a Chinese",NewFont ("Song Body", -, FontStyle.Bold), Brushes.blue,NewPointF ( in, in)); }
C#graphics Drawing