使用到Form1_paint(object sender,PaintEventArgs e),图片显示不出来
我是c#初学者,此次用到了这个程序privatevoidForm1_Paint(objectsender,PaintEventArgse){FileInfofi=newF...
我是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);这行代码么??
请高手给予解答噢~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
难道不能自动生成,要手动加进去????? 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询