IButtonControl 인터페이스

정의

컨트롤이 폼에서 단추처럼 동작할 수 있습니다.

public interface class IButtonControl
public interface IButtonControl
type IButtonControl = interface
Public Interface IButtonControl
파생

예제

다음 예제에서 상속 되는 ButtonBase 클래스 및 구현을 IButtonControl 인터페이스입니다. 구현에 추가 되는 DialogResult 속성 및 NotifyDefaultPerformClick 메서드.

#using <System.dll>
#using <System.Drawing.dll>
#using <System.Windows.Forms.dll>

using namespace System;
using namespace System::Windows::Forms;
using namespace System::Drawing;

public ref class MyButton: public ButtonBase, public IButtonControl
{
private:
   System::Windows::Forms::DialogResult myDialogResult;

public:
   MyButton()
   {
      // Make the button White and a Popup style
      // so it can be distinguished on the form.
      this->FlatStyle = ::FlatStyle::Popup;
      this->BackColor = Color::White;
   }

   property System::Windows::Forms::DialogResult DialogResult 
   {
      // Add implementation to the IButtonControl.DialogResult property.
      virtual System::Windows::Forms::DialogResult get()
      {
         return this->myDialogResult;
      }

      virtual void set( System::Windows::Forms::DialogResult value )
      {
         if ( Enum::IsDefined( System::Windows::Forms::DialogResult::typeid, value ) )
         {
            this->myDialogResult = value;
         }
      }
   }

   // Add implementation to the IButtonControl.NotifyDefault method.
   virtual void NotifyDefault( bool value )
   {
      if ( this->IsDefault != value )
      {
         this->IsDefault = value;
      }
   }

   // Add implementation to the IButtonControl.PerformClick method.
   virtual void PerformClick()
   {
      if ( this->CanSelect )
      {
         this->OnClick( EventArgs::Empty );
      }
   }
};
using System;
using System.Windows.Forms;
using System.Drawing;

public class MyButton : ButtonBase, IButtonControl
{
    private DialogResult myDialogResult;

    public MyButton()
    {
        // Make the button White and a Popup style
        // so it can be distinguished on the form.
        this.FlatStyle = FlatStyle.Popup;
        this.BackColor = Color.White;
    }
        
    // Add implementation to the IButtonControl.DialogResult property.
    public DialogResult DialogResult
    {
        get
        {
            return this.myDialogResult;
        }

        set
        {
            if(Enum.IsDefined(typeof(DialogResult), value))				
            {
                this.myDialogResult = value;
            }
        }	
    }

    // Add implementation to the IButtonControl.NotifyDefault method.
    public void NotifyDefault(bool value)
    {
        if(this.IsDefault != value)
        {
            this.IsDefault = value;
        }
    }

    // Add implementation to the IButtonControl.PerformClick method.
    public void PerformClick()
    {
        if(this.CanSelect)
        {
            this.OnClick(EventArgs.Empty);
        }
    }
}
Imports System.Windows.Forms
Imports System.Drawing


Public Class MyButton
   Inherits ButtonBase
   Implements IButtonControl 
   Private myDialogResult As DialogResult
      
   Public Sub New()
      ' Make the button White and a Popup style      ' so it can be distinguished on the form.
      Me.FlatStyle = FlatStyle.Popup
      Me.BackColor = Color.White
   End Sub
   
   ' Add implementation to the IButtonControl.DialogResult property.
   Public Property DialogResult() As DialogResult Implements IButtonControl.DialogResult
      Get
         Return Me.myDialogResult
      End Get
      
      Set
         If [Enum].IsDefined(GetType(DialogResult), value) Then
            Me.myDialogResult = value
         End If
      End Set
   End Property
   
   ' Add implementation to the IButtonControl.NotifyDefault method.
   Public Sub NotifyDefault(value As Boolean) Implements IButtonControl.NotifyDefault
      If Me.IsDefault <> value Then
         Me.IsDefault = value
      End If
   End Sub 
      
   ' Add implementation to the IButtonControl.PerformClick method.
   Public Sub PerformClick() Implements IButtonControl.PerformClick
      If Me.CanSelect Then
         Me.OnClick(EventArgs.Empty)
      End If
   End Sub

End Class

설명

이 인터페이스를 구현할 수 있습니다의 예에는 기본 및 취소 단추 처리입니다. 기본 단추에는 대화 상자를 닫은 것 처럼 폼에 대 한 처리 되지 않은 ENTER 키 입력 되 면 알림이 표시 됩니다. 마찬가지로, 취소 단추는 처리 되지 않은 ESC 키를 입력 폼에서 훨씬 대화 상자 해제와 같은 때마다 알림이 표시 됩니다.

구현자 참고

단추 컨트롤 역할을 하는 클래스에서 이 인터페이스를 구현합니다. 이 인터페이스의 멤버는 부모 폼에 을 DialogResult 제공하거나 이벤트를 수행하는 Click 기능 또는 폼의 기본 단추 역할을 하는 것과 같은 기본 단추 기능을 제공합니다.

속성

DialogResult

단추를 클릭할 때 부모 폼에 반환되는 값을 가져오거나 설정합니다.

메서드

NotifyDefault(Boolean)

해당 모양과 동작이 적절하게 조정되도록 이 단추가 기본 단추임을 컨트롤에 알립니다.

PerformClick()

컨트롤에 대해 Click 이벤트를 생성합니다.

적용 대상

추가 정보