次の方法で共有


IButtonControl.NotifyDefault メソッド

コントロールに、それが既定のボタンであり、外観と動作が調整されていることが通知されます。

Sub NotifyDefault( _
   ByVal value As Boolean _)
[C#]
void NotifyDefault(
   boolvalue);
[C++]
void NotifyDefault(
   boolvalue);
[JScript]
function NotifyDefault(
   value : Boolean);

パラメータ

  • value
    コントロールが既定のボタンとして動作する場合は true 。それ以外の場合は false

解説

このメソッドが親フォームに呼び出され、コントロールを既定のボタンにします。既定のボタンの境界線は、特に太く設定されています。

使用例

[Visual Basic, C#, C++] ButtonBase クラスから継承し、 IButtonControl インターフェイスを実装する例を次に示します。実装は、 DialogResult プロパティおよび NotifyDefault メソッドと PerformClick メソッドに追加されます。

 
Imports System
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

[C#] 
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);
        }
    }
}

[C++] 
#using <mscorlib.dll>
#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 __gc 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;
   }

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

   __property void set_DialogResult( System::Windows::Forms::DialogResult value )
   {
      if(Enum::IsDefined(__typeof(System::Windows::Forms::DialogResult),__box(value)))                
      {
         this->myDialogResult = value;
      }
   }    

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

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

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ

参照

IButtonControl インターフェイス | IButtonControl メンバ | System.Windows.Forms 名前空間