代码如下: public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.Paint+=new PaintEventHandler(Form1_Paint);
}
protected override void OnPaint(PaintEventArgs e)
{
//Graphics g = e.Graphics;
//g.DrawEllipse(new Pen(Color.Red, 50), new Rectangle(100, 200, 48, 20));
//g.DrawString("Test !",new Font("Courier New",40f,FontStyle.Italic),new HatchBrush(HatchStyle.Cross,Color.Teal),new Point(10,16));
} private void Form1_Paint(object sender, PaintEventArgs e)
{
Graphics g = this.CreateGraphics();
//g.DrawEllipse(new Pen(Color.Red, 50), new Rectangle(100, 200, 48, 20));
g.DrawString("Test !",new Font("Courier New",40f,FontStyle.Italic),new HatchBrush(HatchStyle.Cross,Color.Teal),new Point(10,16));
}
}当写在Onpaint中时,可以实现。但是写到Form1_Paint中,貌似,该事件不执行,断点试过了。求解惑.
分不多,见谅。
{
public Form1()
{
InitializeComponent();
this.Paint+=new PaintEventHandler(Form1_Paint);
}
protected override void OnPaint(PaintEventArgs e)
{
//Graphics g = e.Graphics;
//g.DrawEllipse(new Pen(Color.Red, 50), new Rectangle(100, 200, 48, 20));
//g.DrawString("Test !",new Font("Courier New",40f,FontStyle.Italic),new HatchBrush(HatchStyle.Cross,Color.Teal),new Point(10,16));
} private void Form1_Paint(object sender, PaintEventArgs e)
{
Graphics g = this.CreateGraphics();
//g.DrawEllipse(new Pen(Color.Red, 50), new Rectangle(100, 200, 48, 20));
g.DrawString("Test !",new Font("Courier New",40f,FontStyle.Italic),new HatchBrush(HatchStyle.Cross,Color.Teal),new Point(10,16));
}
}当写在Onpaint中时,可以实现。但是写到Form1_Paint中,貌似,该事件不执行,断点试过了。求解惑.
分不多,见谅。
事件处理器的调用是在Control.OnPaint里处理的
{
Base.OnPaint(e);//这样试试
Graphics g = this.CreateGraphics();
//g.DrawEllipse(new Pen(Color.Red, 50), new Rectangle(100, 200, 48, 20));
g.DrawString("Test !",new Font("Courier New",40f,FontStyle.Italic),new HatchBrush(HatchStyle.Cross,Color.Teal),new Point(10,16));
}