制作 Winforms ImageButton 类 (C#) 时遇到了一些麻烦。我的 ImageButton 类实现了 IButtonControl 接口,但是当我将其添加到窗体中,并将按钮的 DialogResult 设置为 'OK' ,然后在窗体上调用 ShowDialog() 时,按下按钮不会关闭窗体并返回 DialogResult,如正常的 Winforms 按钮控件可以。
这是我对 ImageButton 的实现,您可以随意使用它。
/// <summary>
/// A control that displays an image and responds to mouse clicks on the image.
/// </summary>
[PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
[Designer(typeof(ImageButtonDesigner))]
[ToolboxItem(typeof(ImageButtonToolboxItem))]
public class ImageButton : PictureBox, IButtonControl, INotifyPropertyChanged
{
#region Constructors
/// <summary>
/// Initializes a new instance of the ImageButton class using the default initial values.
/// </summary>
public ImageButton()
{
DoubleBuffered = …
Run Code Online (Sandbox Code Playgroud)