首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用显示对话框传递数据通过窗体,但不关闭事件

使用显示对话框传递数据通过窗体,但不关闭事件
EN

Stack Overflow用户
提问于 2021-04-27 09:34:41
回答 1查看 22关注 0票数 0

我有一个第一个表单(form_notice_hashtag),名为:

代码语言:javascript
复制
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

在form_notice_hashtag_1中,我有一个按钮调用第二个表单(form_recherche_thesaurus),如下所示:

代码语言:javascript
复制
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_thesaurus中,我有一个datagridview,列出了一些单词。用户可以选择一个单词,然后单击form_recherche_thesaurus中的一个按钮,这个单词将被添加到form_notice_hashtag的文本框中。

代码语言:javascript
复制
Private Sub thesaurus_ok_button_Click(sender As Object, e As EventArgs) Handles thesaurus_ok_button.Click
        Dim list_terms_array As String()
         Select Case Owner.Name.ToString
            Case "form_notice_hashtag"
                list_terms_array = Split(Remove_Duplicates_From_Strings_With_SemiColon(form_notice_hashtag.hashtag_descripteurs_txtbox.Text & ";" & selected_term), ";")
                form_notice_hashtag.hashtag_descripteurs_txtbox.Text = (String.Join(";", list_terms_array.Where(Function(s) Not String.IsNullOrEmpty(s))))
          End Select
    End Sub

我使用了select,因为这种机制将与form_notice_hashtag以外的其他表单使用相同的方式。

问题: form_notice_hashtag中的文本框没有填充选定的关键字。我想是因为form_notice_hashtag的名字。

我不能像这里解释的那样使用这个解决方案,将值从一个窗体发送到另一个窗体,因为我理解(可能很糟糕),只有当第二个表单(在我的情况下是form_recherche_thesaurus)关闭(即关闭是触发器)时,这个解决方案才能工作,而我不想这样做。

我该怎么做?

EN

回答 1

Stack Overflow用户

发布于 2021-04-27 10:37:16

感谢jmcilhinney和他的博客的这一页,这里的解决方案允许将多个数据从被调用的表单(form_recherche_thesaurus)传输到调用表单(form_notice_hashtag),而不关闭被调用的表单。

代码语言:javascript
复制
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
代码语言:javascript
复制
Public Class form_recherche_thesaurus
    Public Event TextBoxTextChanged As EventHandler
    Private term_thesaurus As String
    
    Public Property selected_term() As String
        Get
            Return term_thesaurus
        End Get
        Set(ByVal value As String)
            term_thesaurus = value
        End Set
    End Property
    
    Private Sub thesaurus_ok_button_Click(sender As Object, e As EventArgs) Handles thesaurus_ok_button.Click
        Dim list_terms_array As String()        
        Me.selected_term = Me.thesaurus_search_results_datagrid.Item(0, Me.thesaurus_search_results_datagrid.CurrentRow.Index).Value
        Me.DialogResult = DialogResult.OK
        RaiseEvent TextBoxTextChanged(Me, EventArgs.Empty)
    End Sub
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67280521

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档