我的程序正在打开一个与我想要的不同的形式。答案解决了。
基本上我想在程序启动时停止打开表单,但是当它手动打开时(按下按钮),它会更新数据。问题的第二部分尚未解决,但第一部分已经解决了。
答案 0 :(得分:0)
您可以尝试这样的事情:
Public Class HomeForm
Private WithEvents m_DataChangeForm As DataChangeForm
Private Sub HomeForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
m_DataChangeForm = New DataChangeForm()
m_DataChangeForm.Show()
End Sub
Private Sub OnDataSourceChanged(sender As Object, args As EventArgs) Handles m_DataChangeForm.OnDataSourceChanged
MessageBox.Show("Data source changed!")
End Sub
End Class
Public Class DataChangeForm
Inherits Form
Public Event OnDataSourceChanged(sender As Object, args As EventArgs)
Private WithEvents m_Button As Button
Public Sub New()
m_Button = New Button()
m_Button.Text = "Change"
m_Button.Parent = Me
End Sub
Public Sub buttonClick(sender As Object, args As EventArgs) Handles m_Button.Click
RaiseEvent OnDataSourceChanged(sender, args)
Me.Close()
End Sub
End Class
在HomeForm之前显示您的表单的原因因为您调用ShowDialog,它会一直阻塞,直到DataChangeForm关闭。
答案 1 :(得分:0)
您应该从"加载"到"显示"事件
Private Sub Homefrm_Shown(sender As Object, e As EventArgs) Handles Me.Shown
Using fp = New dataChangefrm(m_database)
If fp.ShowDialog() = DialogResult.OK Then
uwgHome.DataSource = Nothing
loadData()
End If
End Using
Me.Location = New Point(0, 0)
loadData()
End Sub
请在第一行查看Handle。这取决于你的项目。