使用到Form1_paint(object sender,PaintEventArgs e),图片显示不出来

来源:百度知道 编辑:UC知道 时间:2024/06/05 11:13:07
我是c#初学者,此次用到了这个程序
private void Form1_Paint(object sender, PaintEventArgs e)
{
FileInfo fi = new FileInfo("logo.jpg");
string s=fi.DirectoryName;

Graphics g = this.CreateGraphics();
Bitmap image1 = (Bitmap)Image.FromFile(s+"\\logo.jpg", true);
int x = 100;
int y = 100;
Point myPoint = new Point(x, y);
g.DrawImage(image1, myPoint);

Graphics g1 = this.CreateGraphics();
g1.ScaleTransform(0.8f, 0.6f);
g1.DrawImage(image1, 200, 50);
}
双击空白窗体后我就把此程序打入,但和标准程序相比了一下发现在Form1.Designer.cs中少了
this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint);这行代码,我把这行代码添加到我的程序中时,图片才得以显示。
我搞不明白的是,是我少添加了什么东西程序才不能生成this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint);这行代码么??
请高手给予解

因为你是双击后在代码里面写的呀,双击VS默认添加的是Form_Load事件。
你如果想要自动生成,那就在Form属性里面选那个闪电符号(事件),然后双击里面的Paint部分。这时VS就自动帮你添了