我是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);这行代码么??
请高手给予解答噢~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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);这行代码么??
请高手给予解答噢~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*****************************************************************************
欢迎使用CSDN论坛专用阅读器 : CSDN Reader(附全部源代码) http://feiyun0112.cnblogs.com/
this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint);
2. 这里不要使用CreateGraphics方法来创建Graphics对象。要使用事件参数e的Graphics属性。