Control.ProcessMnemonic(Char) Metode

Definisi

Memproses karakter mnemonic.

protected:
 virtual bool ProcessMnemonic(char charCode);
protected public:
 virtual bool ProcessMnemonic(char charCode);
protected virtual bool ProcessMnemonic(char charCode);
protected internal virtual bool ProcessMnemonic(char charCode);
abstract member ProcessMnemonic : char -> bool
override this.ProcessMnemonic : char -> bool
Protected Overridable Function ProcessMnemonic (charCode As Char) As Boolean
Protected Friend Overridable Function ProcessMnemonic (charCode As Char) As Boolean

Parameter

charCode
Char

Karakter yang akan diproses.

Mengembalikan

true jika karakter diproses sebagai mnemonic oleh kontrol; jika tidak, false.

Contoh

Contoh kode berikut menunjukkan ekstensi kelas tombol yang mengambil alih ProcessMnemonic metode untuk menunjukkan perilaku kustom. Contoh ini juga menunjukkan penggunaan CanSelect properti dan IsMnemonic . Untuk menjalankan contoh ini, tempelkan kode berikut setelah kelas formulir, dalam file yang sama. Tambahkan tombol jenis MnemonicButton ke formulir.

// This button is a simple extension of the button class that overrides
// the ProcessMnemonic method.  If the mnemonic is correctly entered,  
// the message box will appear and the click event will be raised.  
// This method makes sure the control is selectable and the 
// mnemonic is correct before displaying the message box
// and triggering the click event.
public ref class MyMnemonicButton: public Button
{
protected:
   bool ProcessMnemonic( char inputChar )
   {
      if ( CanSelect && IsMnemonic( inputChar, this->Text ) )
      {
         MessageBox::Show( "You've raised the click event "
         "using the mnemonic." );
         this->PerformClick();
         return true;
      }

      return false;
   }

};
// This button is a simple extension of the button class that overrides
// the ProcessMnemonic method.  If the mnemonic is correctly entered,  
// the message box will appear and the click event will be raised.  
public class MyMnemonicButton : Button
{
    // This method makes sure the control is selectable and the 
    // mneumonic is correct before displaying the message box
    // and triggering the click event.
    protected override bool ProcessMnemonic(char inputChar)
    {
        if (CanSelect && IsMnemonic(inputChar, this.Text))
        {
            MessageBox.Show("You've raised the click event " +
                "using the mnemonic.");
            this.PerformClick();
            return true;
        }
        return false;
    }
}
' This button is a simple extension of the button class that overrides
' the ProcessMnemonic method.  If the mnemonic is correctly entered,  
' the message box will appear and the click event will be raised.  
Public Class MyMnemonicButton
    Inherits Button

    ' This method makes sure the control is selectable and the 
    ' mneumonic is correct before displaying the message box
    ' and triggering the click event.
    <System.Security.Permissions.UIPermission( _
    System.Security.Permissions.SecurityAction.Demand, Window:=UIPermissionWindow.AllWindows)> _
    Protected Overrides Function ProcessMnemonic( _
        ByVal inputChar As Char) As Boolean

        If (CanSelect And IsMnemonic(inputChar, Me.Text)) Then
            MessageBox.Show("You've raised the click event " _
                & "using the mnemonic.")
            Me.PerformClick()
            Return True
        End If
        Return False
    End Function

End Class

Keterangan

Metode ini dipanggil untuk memberikan kontrol kesempatan untuk memproses karakter mnemonic. Metode harus menentukan apakah kontrol dalam keadaan untuk memproses mnemonics dan apakah karakter yang diberikan mewakili mnemonic. Jika demikian, metode harus melakukan tindakan yang terkait dengan mnemonic dan mengembalikan true. Jika tidak, metode harus mengembalikan false. Implementasi metode ini sering menggunakan IsMnemonic metode untuk menentukan apakah karakter yang diberikan cocok dengan mnemonic dalam teks kontrol.

Contohnya:

if (CanSelect && IsMnemonic(charCode, MyControl.Text) {
      // Perform action associated with mnemonic.
       }

Implementasi ProcessMnemonic default metode ini hanya kembali false untuk menunjukkan bahwa kontrol tidak memiliki mnemonic.

Berlaku untuk

Lihat juga