所以,我需要为客户做一个程序,他想要一个搜索栏。所以我做到了,一切都很完美,但我把它放在了我的主要形式中。现在,我想把它放在一个类中,但是当我初始化程序时,它给了我以下错误
An error occurred while creating the form. For more information,
see Exception.InnerException. The error is: The form is self-reference during
construction from a default instance, which led to infinite recursion. In the
constructor of the form, refer to the form using 'Me'.
我试图把 Me.Rbtn_X... 放进去,但它不认识它。
初始化
' Main form
Public Sub New()
InitializeComponent()
Initialize_search()
End Sub
初始化搜索()
' Main form
' search is initialize like this :
' Dim search as New Research
Private Sub Initialize_search()
search.generate_autocomplete()
End Sub
生成自动完成()
' Research class
Sub generate_autocomplete()
' Main_form = Main form
Dim field = ""
' This is the place where the program fail
If Main_form.RbtnR_avancee_contact.Checked Then
field = "personneressource"
Else
field = "beneficiaire"
End if
' ....
End Sub
有什么我不明白的,或者不可能那样做吗?
编辑:添加 Form_shown 事件
Public Sub New()
InitializeComponent()
' Initialize_search()
End Sub
Private Sub Form_personne_Shown(sender As Object, e As EventArgs) Handles Me.Shown
MessageBox.Show("You are in the Form.Shown event.")
End Sub