C# と VB.NET の質問掲示板

わんくま同盟

ASP.NET、C++/CLI、Java 何でもどうぞ

C# と VB.NET の入門サイト

■102996 / 1階層)  RadioButtonの初期設定とMDI子フォームとの動作に
□投稿者/ KOZ (436回)-(2024/03/10(Sun) 00:34:26)
2024/03/10(Sun) 00:46:33 編集(投稿者)
Friend WithEvents RadioButton1 As RadioButton

Private Sub RadioButton1_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton1.CheckedChanged

End Sub

このように書くと、WidthEvent をつけたフィールドはプロパティとしてコンパイルされ、次の様になります。

Private _RadioButton1 As RadioButton

Friend Property RadioButton1 As RadioButton
    Get
        Return _RadioButton1
    End Get
    Set(value As RadioButton)
        If _RadioButton1 IsNot Nothing Then
            RemoveHandler _RadioButton1.CheckedChanged, AddressOf RadioButton1_CheckedChanged
        End If
        _RadioButton1 = value
        If _RadioButton1 IsNot Nothing Then
            AddHandler _RadioButton1.CheckedChanged, AddressOf RadioButton1_CheckedChanged
        End If
    End Set
End Property

Private Sub RadioButton1_CheckedChanged(sender As Object, e As EventArgs) ' Handles は無くなる

End Sub

なので次のコードを実行すると

RemoveHandler RadioButton1.CheckedChanged, AddressOf RadioButton1_CheckedChanged  'イベントが解除される
RadioButton1.Checked = True                                                       '値が変更されても飛ばない 
AddHandler RadioButton1.CheckedChanged, AddressOf RadioButton1_CheckedChanged     '変更された後なので飛ばない

ということになります。

編集キー/

前の記事(元になった記事) 次の記事(この記事の返信)
←RadioButtonの初期設定とMDI子フォームとの動作に /みか →Re[2]: RadioButtonの初期設定とMDI子フォームとの動作に /みか
 
上記関連ツリー

RadioButtonの初期設定とMDI子フォームとの動作に / みか (24/03/09(Sat) 20:26) #102995
RadioButtonの初期設定とMDI子フォームとの動作に / KOZ (24/03/10(Sun) 00:34) #102996 ←Now
  └ Re[2]: RadioButtonの初期設定とMDI子フォームとの動作に / みか (24/03/10(Sun) 19:14) #102998
    └ Re[3]: RadioButtonの初期設定とMDI子フォームとの動作に / KOZ (24/03/11(Mon) 11:54) #103001

上記ツリーを一括表示 / 上記ツリーをトピック表示
 
上記の記事へ返信