TabControl.Selected イベント

定義

タブが選択されると発生します。

public:
 event System::Windows::Forms::TabControlEventHandler ^ Selected;
public event System.Windows.Forms.TabControlEventHandler Selected;
public event System.Windows.Forms.TabControlEventHandler? Selected;
member this.Selected : System.Windows.Forms.TabControlEventHandler 
Public Custom Event Selected As TabControlEventHandler 

イベントの種類

次のコード例では、このメンバーの使用方法を示します。 この例では、イベント ハンドラーがイベントの Selected 発生を報告します。 このレポートは、イベントが発生したタイミングを確認するのに役立ち、デバッグに役立ちます。 複数のイベントまたは頻繁に発生するイベントを報告するには、 を Console.WriteLine に置き換えるかMessageBox.Show、複数行TextBoxにメッセージを追加することを検討してください。

コード例を実行するには、 という名前TabControl1の型TabControlのインスタンスを含むプロジェクトに貼り付けます。 次に、イベント ハンドラーがイベントに関連付けられていることを確認します Selected

private void TabControl1_Selected(Object sender, TabControlEventArgs e) {

System.Text.StringBuilder messageBoxCS = new System.Text.StringBuilder();
messageBoxCS.AppendFormat("{0} = {1}", "TabPage", e.TabPage );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "TabPageIndex", e.TabPageIndex );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "Action", e.Action );
messageBoxCS.AppendLine();
MessageBox.Show(messageBoxCS.ToString(), "Selected Event" );
}
Private Sub TabControl1_Selected(sender as Object, e as TabControlEventArgs) _ 
     Handles TabControl1.Selected

    Dim messageBoxVB as New System.Text.StringBuilder()
    messageBoxVB.AppendFormat("{0} = {1}", "TabPage", e.TabPage)
    messageBoxVB.AppendLine()
    messageBoxVB.AppendFormat("{0} = {1}", "TabPageIndex", e.TabPageIndex)
    messageBoxVB.AppendLine()
    messageBoxVB.AppendFormat("{0} = {1}", "Action", e.Action)
    messageBoxVB.AppendLine()
    MessageBox.Show(messageBoxVB.ToString(),"Selected Event")

End Sub

注釈

で現在のタブが変更 TabControlされると、次のイベントが次の順序で発生します。

これらのイベントを使用すると、 が無効な状態の場合 TabPage にタブ変更を取り消したり、新しく表示された TabPageの状態を更新したりするなどのタスクを実行できます。

現在のタブは、ユーザーがタブをクリックしたとき、または SelectTab メソッドを呼び出DeselectTabすとき、または または プロパティのSelectedIndexSelectedTab値を変更したときに変更されます。

適用対象

こちらもご覧ください