关于自定义类
我写了个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里没有反应,不知道是为什么?请帮帮忙
------解决方案--------------------OnPaint函数中的Point坐标太大了,已经超过了Label的默认大小,改为
  p.X=0;  
  p.Y=0;  
就OK了
------解决方案--------------------label工作区域很小的
你这是在相对于它的坐标X=100 ,Y=100的地方画的啊。。。
把label的AutoSize属性设置为 False;再把它拉大看看
------解决方案--------------------       public ImputClass(): base()  
{  
           this.Click += new EventHandler(MethodLabel_Click);  
AutoSize=False;
size=(200,200);
}
------解决方案-------------------- protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)  
       {  
base.OnPaint(e);
           Image myImage = Image.FromFile(Imagedir);  
           Point p=new Point();  
           p.X=100;  
           p.Y=100;  
           e.Graphics.DrawImage(myImage, p);  
       }