关于自定义类
我写了个Label的自定义类,OnPaint事件是读入一个图片,想在Form中显示;
using System;
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.ComponentModel;
namespace workflowTest
{
class ImputClass:System.Windows.Forms.Label
{
//图片的路径
string Imagedir=@"E:\Input_Document.jpg";
public ImputClass(): base()
{
}
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
Image myImage = Image.FromFile(Imagedir);
Point p=new Point();
p.X=100;
p.Y=100;
e.Graphics.DrawImage(myImage, p);
}
}
}
下面是form中调用的代码:
ImputClass haha = new ImputClass();
this.Controls.Add(haha);
Point p=new Point();
p.X=100;
p.Y=100;
haha.Location=p;
但是form里没有反应,不知道是为什么?请帮帮忙