This is probably simple, but I cannot figure out how to do this.
I have a bunch of form elements created by a form constructor declared as (in frmAquRun.Designer.vb)
Public WithEvents btnAquRunEvent1 As VisibiltyButtonLib.VisibilityButton
Public WithEvents btnAquRunEvent2 As VisibiltyButtonLib.VisibilityButton
... etc.
And I basically want to be able to provide a function number to access each of these fields. Therefore, I wrote this function. (in frmAquRun.vb)
Const EVENT_BUTTON_PREFIX As String = "btnAquRunEvent"
Public Function getEventButton(ByVal id As Integer) As Windows.Forms.Button
Dim returnButton As Windows.Forms.Button = Nothing
Try
returnButton = DirectCast(Me.GetType().InvokeMember(eventButtonName, Reflection.BindingFlags.GetField Or Reflection.BindingFlags.Public Or Reflection.BindingFlags.Instance, Nothing, Me, Nothing), Windows.Forms.Button)
Catch ex As Exception
End Try
Return returnButton
End Function
But it always seems that field generation is not detected. The message in the exception is "Field" ATSIS_ControlProgram.frmAquRun.btnAquRunEvent1 "not found".
The namespace and form name in the message are correct. Any idea what I'm doing wrong?
source
share