1 つの親パネルに追加するパネルがたくさんあり、すべてのパネルにイベント リスナーを追加したいのですが、それらがすべて親に追加されるまでは追加しません (イベント リスナーを起動させたくないため)。新しいパネルが追加されるたびに)。だから私は次のコードを使用しています:
Dim temp_object As question_bar = Nothing
For Each q As Object In review_holder.Controls
If TypeOf q Is question_bar Then
temp_object = q
AddHandler temp_object.Resize, AddressOf temp_object.resize_me
End If
Next
For Each q As Object In review_holder.Controls
If TypeOf q Is question_bar Then
temp_object = q
temp_object.resize_me()
End If
Next
しかし、resize_me() サブルーチンが各コントロールに対して 2 回起動されていることに気付きました。私はそれを一度だけ発射したい。だから私はこのコードを使ってそれをたどった
MsgBox((New System.Diagnostics.StackTrace).GetFrame(1).GetMethod.Name)
そして、呼び出されるたびに、呼び出しメソッドがこのサブルーチンと _Lambda$_365 の両方であることがわかります。それは一体何ですか?それがどこから来ているのかを知るにはどうすればよいですか?
ところで、これは VS2012 を使用した winforms アプリです。
編集 - - - - - - - - - - - - - - - - - - - - - - - - - -----------------------
Public Sub resize_me()
MsgBox((New System.Diagnostics.StackTrace).GetFrame(1).GetMethod.Name)
If Me.minimized = True Then
Me.Height = 0
Exit Sub
End If
number_panel.Width = my_parent.number_width
number_text.Width = my_parent.number_width
number_separator.Left = number_panel.Right
question_panel.Left = number_separator.Right
question_panel.Width = question_panel.Parent.Width * initial_question_width + (question_padding * 2)
End Sub