在做WinForm时,想做一个像Asp.Net里的ImageButton的控件,于是自己写了一个自定义控件,名为:ImageButton,继承PictureBox类,并实现IButtonControl接口,但是实现IButtonControl接口时必须重写IButtonControl的NotifyDefault(bool value) 和 PerformClick()方法,还有 DialogResult { get; set; }属性,我的代码如下,可是里面的PerformClick()方法我不会写,请高手指导一下。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
namespace MyControls
{
public partial class ImageButton : PictureBox,IButtonControl
{
private DialogResult dialogResult;
public ImageButton()
{
InitializeComponent();
}
public void PerformClick()
{
//这里面的代码不会写
}
protected override void OnPaint(PaintEventArgs pe)
{
// TODO: 在此处添加自定义绘制代码
// 调用基类 OnPaint
base.OnPaint(pe);
}
public virtual void NotifyDefault(bool value)
{
}
public virtual DialogResult DialogResult
{
get
{
return this.dialogResult;
}
set
{
this.dialogResult = value;
}
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
namespace MyControls
{
public partial class ImageButton : PictureBox,IButtonControl
{
private DialogResult dialogResult;
public ImageButton()
{
InitializeComponent();
}
public void PerformClick()
{
//这里面的代码不会写
}
protected override void OnPaint(PaintEventArgs pe)
{
// TODO: 在此处添加自定义绘制代码
// 调用基类 OnPaint
base.OnPaint(pe);
}
public virtual void NotifyDefault(bool value)
{
}
public virtual DialogResult DialogResult
{
get
{
return this.dialogResult;
}
set
{
this.dialogResult = value;
}
}
}
}