Procedure 1:
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Drawing;using System.Windows.Forms;namespace PaintEvent{ class Program { static void Main(string[] args) { Form form = new Form(); form.Text = "PaintEvent"; form.Paint +=new PaintEventHandler(MyPaintHander); Application.Run(form); } static void MyPaintHander(object objSender , PaintEventArgs pea) { Graphics gl = pea.Graphics; Console.WriteLine("PaintEvent"); gl.Clear(Color.Chocolate); } }}
Procedure 2:
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Drawing;using System.Windows.Forms;namespace PaintHello{ class Program { static void Main(string[] args) { Form form = new Form(); form.Text = "PaintHello"; form.BackColor = Color.White; form.Paint += new PaintEventHandler(MyPaintHander); Application.Run(form); } static void MyPaintHander(object objSender, PaintEventArgs pea) { Form form = (Form)objSender; Graphics gl = pea.Graphics; gl.DrawString("PaintHello",form.Font,Brushes.Black,0,0); } }}
Procedure 3:
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Drawing;using System.Windows.Forms;namespace PaintTwoForms{ class Program { static Form form1 = new Form(); static Form form2 = new Form(); static void Main(string[] args) { form1.Text = "First Form"; form1.BackColor = Color.White; form1.Paint += new PaintEventHandler(MyPaintHander); form2.Text = "Second Form"; form2.BackColor = Color.White; form2.Paint += new PaintEventHandler(MyPaintHander); form2.Show(); Application.Run(form1); } static void MyPaintHander(object objSender, PaintEventArgs pea) { Form form = (Form)objSender; Graphics gl = pea.Graphics; string str; if (form == form1) { str = "Hello From the form1"; } else str = "Hello From the form2"; gl.DrawString(str, form.Font, Brushes.Black, 0, 0); } }}
Procedure 4:
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Drawing;using System.Windows.Forms;namespace TwoPaintHanders{ class Program { static void Main(string[] args) { Form form1 = new Form(); form1.Text = "TwoPaintHanders"; form1.BackColor = Color.White; form1.Paint += new PaintEventHandler(MyPaintHander1); form1.Paint += new PaintEventHandler(MyPaintHander2); Application.Run(form1); } static void MyPaintHander1(object objSender, PaintEventArgs pea) { Form form = (Form)objSender; Graphics gl = pea.Graphics; gl.DrawString("First PaintEventHandler", form.Font, Brushes.Black, 0, 0); } static void MyPaintHander2(object objSender, PaintEventArgs pea) { Form form = (Form)objSender; Graphics gl = pea.Graphics; gl.DrawString("Second PaintEventHandler", form.Font, Brushes.Black, 0, 100); } }}
Procedure 5:
using System;using System.Drawing;using System.Windows.Forms;class HelloWorld: Form{ static void Main(string[] args) { Application.Run(new HelloWorld()); } public HelloWorld() { Text = "HelloWorld"; BackColor = Color.Write; } protected override void OnPaint(PaintEventArgs pea) { Graphics gl = pea.Graphics; gl.DrawString("Hello Windows Forms!", Font, Brushes.Black, 0, 0); }}
Procedure 6:
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Drawing;using System.Windows.Forms;namespace inHeritHelloWorld{ class inHeritHelloWorld : HelloWorld { public new static void Main(string[] args) { Application.Run(new inHeritHelloWorld()); } public inHeritHelloWorld() { Text = "inHerit" + Text; } protected override void OnPaint(PaintEventArgs pea) { Graphics gl = pea.Graphics; gl.DrawString("Hello From inHeritHelloWorld!", Font, Brushes.Black, 0, 0); } }}