Vb.net 使用showdialog通过表单传递数据,但不关闭事件
我有一个第一个表单(表单通知标签),叫做:Vb.net 使用showdialog通过表单传递数据,但不关闭事件,vb.net,forms,Vb.net,Forms,我有一个第一个表单(表单通知标签),叫做: Public Sub afficher_hashtag(hashtag As String, plateforme_hashtag As String) Dim form_notice_hashtag_1 As New form_notice_hashtag form_notice_hashtag_1.StartPosition = FormStartPosition.CenterScreen form_
Public Sub afficher_hashtag(hashtag As String, plateforme_hashtag As String)
Dim form_notice_hashtag_1 As New form_notice_hashtag
form_notice_hashtag_1.StartPosition = FormStartPosition.CenterScreen
form_notice_hashtag_1.Show()
End Sub
Private Sub hashtag_thesaurus_search_button_Click(sender As Object, e As EventArgs) Handles hashtag_thesaurus_search_button.Click
Dim form_recherche_thesaurus_1 As New form_recherche_thesaurus With {
.StartPosition = FormStartPosition.Manual,
.Location = New Point(Me.Left + Me.Width, Me.Top)
}
form_recherche_thesaurus_1.ShowDialog(Me)
End Sub
在form_notice_hashtag_1中,我有一个按钮调用第二个表单(form_recherche_thesaurus),如下所示:
Public Sub afficher_hashtag(hashtag As String, plateforme_hashtag As String)
Dim form_notice_hashtag_1 As New form_notice_hashtag
form_notice_hashtag_1.StartPosition = FormStartPosition.CenterScreen
form_notice_hashtag_1.Show()
End Sub
Private Sub hashtag_thesaurus_search_button_Click(sender As Object, e As EventArgs) Handles hashtag_thesaurus_search_button.Click
Dim form_recherche_thesaurus_1 As New form_recherche_thesaurus With {
.StartPosition = FormStartPosition.Manual,
.Location = New Point(Me.Left + Me.Width, Me.Top)
}
form_recherche_thesaurus_1.ShowDialog(Me)
End Sub
在form_recherche_同义词表中,我有一个datagridview,列出了一些单词。用户可以选择一个单词,然后单击form\u recherche\u叙词表中的按钮,该单词将添加到form\u notice\u标签中的文本框中
我使用了select,因为这种机制将以相同的方式用于除form\u notice\u标签之外的其他表单
问题:form_notice_标签中的文本框未填充所选关键字。我想这是因为表单通知标签的命名方式
我不能使用这里解释的解决方案,因为我理解(可能很糟糕)这个解决方案只有在我不想要的第二个表单(在我的例子中是form_recherche_thesaurus)关闭(即关闭是触发器)时才有效
如何继续?多亏了jmchilney和他的这一页,这是一个解决方案,它允许在不关闭被调用表单的情况下,将多个数据从被调用表单(form_recherche_同义词表)传输到调用表单(form_notice_hashtag)
Public Class form_notice_hashtag
Private WithEvents form_recherche_thesaurus_1 As form_recherche_thesaurus
Private selected_thesaurus_term As String
Private Sub form_recherche_thesaurus_1_TextBoxTextChanged(sender As Object, e As EventArgs) Handles form_recherche_thesaurus_1.TextBoxTextChanged
Dim list_terms_array As String() = Split(Remove_Duplicates_From_Strings_With_SemiColon(Me.hashtag_descripteurs_txtbox.Text & ";" & form_recherche_thesaurus_1.selected_term), ";")
Me.hashtag_descripteurs_txtbox.Text = (String.Join(";", list_terms_array.Where(Function(s) Not String.IsNullOrEmpty(s))))
End Sub
Private Sub hashtag_thesaurus_search_button_Click(sender As Object, e As EventArgs) Handles hashtag_thesaurus_search_button.Click
Dim form_recherche_thesaurus_1 As New form_recherche_thesaurus With {
.StartPosition = FormStartPosition.Manual,
.Location = New Point(Me.Left + Me.Width, Me.Top)
}
If Me.form_recherche_thesaurus_1 Is Nothing OrElse Me.form_recherche_thesaurus_1.IsDisposed Then
Me.form_recherche_thesaurus_1 = New form_recherche_thesaurus With {
.StartPosition = FormStartPosition.Manual,
.Location = New Point(Me.Left + Me.Width, Me.Top)
}
Me.form_recherche_thesaurus_1.Show()
End If
Me.form_recherche_thesaurus_1.Activate()
End Sub
End Class
最后一个表单不应该知道调用方的任何信息。它应该只通过公共属性公开数据,就是这样。然后,调用表单负责从该属性获取所需的数据。这样就不需要
Select Case
,因为每个不同的调用表单都确切地知道它需要如何使用数据。我建议你阅读我博客文章的三个部分。谢谢,你的文章对于像我这样的noobs来说非常清晰,写得很好(但是第三部分的例子有点棘手)。我使用了第3部分中的解决方案。