共用方式為


Control.ImeModeChanged 事件

定義

發生於 ImeMode 屬性變更時。

public:
 event EventHandler ^ ImeModeChanged;
public event EventHandler ImeModeChanged;
member this.ImeModeChanged : EventHandler 
Public Custom Event ImeModeChanged As EventHandler 

事件類型

EventHandler

範例

下列程式碼範例是屬性值變更時 Text 所執行的事件處理常式。 類別 Control 有數個名稱模式 PropertyName Changed 的方法,當對應的 PropertyName 值變更 (PropertyName 代表對應屬性的名稱) 時引發。

下列程式碼範例會變更 ForeColor TextBox 顯示貨幣資料的 。 本範例會將文字轉換成十進位數,如果數位為負數,則變更為 ,如果 Color.Black 數位為正數,則為 。 ForeColor Color.Red 此範例需要您有 Form 包含 的 TextBox

private:
   void currencyTextBox_TextChanged( Object^ /*sender*/, EventArgs^ /*e*/ )
   {
      try
      {
         // Convert the text to a Double and determine if it is a negative number.
         if ( Double::Parse( currencyTextBox->Text ) < 0 )
         {
            // If the number is negative, display it in Red.
            currencyTextBox->ForeColor = Color::Red;
         }
         else
         {
            // If the number is not negative, display it in Black.
            currencyTextBox->ForeColor = Color::Black;
         }
      }
      catch ( Exception^ ) 
      {
         // If there is an error, display the text using the system colors.
         currencyTextBox->ForeColor = SystemColors::ControlText;
      }
   }
private void currencyTextBox_TextChanged(object sender, EventArgs e)
{
   try
   {
      // Convert the text to a Double and determine if it is a negative number.
      if(double.Parse(currencyTextBox.Text) < 0)
      {
         // If the number is negative, display it in Red.
         currencyTextBox.ForeColor = Color.Red;
      }
      else
      {
         // If the number is not negative, display it in Black.
         currencyTextBox.ForeColor = Color.Black;
      }
   }
   catch
   {
      // If there is an error, display the text using the system colors.
      currencyTextBox.ForeColor = SystemColors.ControlText;
   }
}
Private Sub currencyTextBox_TextChanged(sender As Object, _ 
  e As EventArgs) Handles currencyTextBox.TextChanged
   Try
      ' Convert the text to a Double and determine if it is a negative number.
      If Double.Parse(currencyTextBox.Text) < 0 Then
         ' If the number is negative, display it in Red.
         currencyTextBox.ForeColor = Color.Red
      Else
         ' If the number is not negative, display it in Black.
         currencyTextBox.ForeColor = Color.Black
      End If
   Catch
      ' If there is an error, display the text using the system colors.
      currencyTextBox.ForeColor = SystemColors.ControlText
   End Try
End Sub

備註

如果屬性是透過程式設計修改或透過互動來變更,就會 ImeMode 引發這個事件。

不支援輸入方法管理員的控制項永遠不會引發此事件。

如需處理事件的詳細資訊,請參閱 處理和引發事件

適用於

另請參閱