IButtonControl 인터페이스
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
컨트롤이 폼의 단추처럼 작동하도록 허용합니다.
public interface class IButtonControl
public interface IButtonControl
type IButtonControl = interface
Public Interface IButtonControl
- 파생
예제
다음 예제에서는 클래스에서 ButtonBase 상속 하 고 인터페이스를 IButtonControl 구현 합니다. 구현은 속성 및 메서드에 NotifyDefaultPerformClick 추가 DialogResult 됩니다.
#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 기능 또는 폼의 기본 단추 역할을 하는 것과 같은 기본 단추 기능을 제공합니다.
속성
| Name | Description |
|---|---|
| DialogResult |
단추를 클릭할 때 부모 폼에 반환되는 값을 가져오거나 설정합니다. |
메서드
| Name | Description |
|---|---|
| NotifyDefault(Boolean) |
컨트롤의 모양과 동작이 그에 따라 조정되도록 컨트롤에 기본 단추임을 알립니다. |
| PerformClick() |
컨트롤에 Click 대한 이벤트를 생성합니다. |