Paint事件
using System;
using System.Windows.Forms;
using System.Threading;
using System.Drawing;
namespace myproject
{
class ConsoleHelloWorld
{
static int j = 0;
public static void Main()
{
Form form = new System.Windows.Forms.Form();
// form.Show();
// Thread.Sleep(2000);
form.Text = "my form";
// Thread.Sleep(3000);
form.Paint += new PaintEventHandler(MyPaintHandler);
Application.Run(form);
/*
string str = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
Date mydate = new Date();
//string str = "abC";
mydate.Year = 10;
System.Console.WriteLine(mydate.Year);
System.Console.WriteLine("hello world");
DialogResult dr = System.Windows.Forms.MessageBox.Show("hello");
System.Console.WriteLine(dr);
System.Console.WriteLine(str);
*/
}//End main method
static void MyPaintHandler(object sender,PaintEventArgs pea)
{
Form form = (Form)sender;
Graphics grfx = pea.Graphics;
grfx.Clear(Color.Chocolate);
j++;
grfx.DrawString("Paint Event" + j ,form.Font,Brushes.Black,0,j);
}
}
class Date
{
int year;
public int Year
{
set
{
year = value;
}
get
{
return year;
}
}
}
}
grfx.DrawString("Paint Event" + j ,form.Font,Brushes.Black,0,j);
为什么这行打出来的字符位置老是相同?是否win form响应不过来?