我最近开始使用 Visual Studio 2010 学习 VB.net,到目前为止我做得很好,但我已经被这个问题困住了几个小时,经过谷歌和堆栈溢出搜索的许多页面后,我来找你.
我有 2 种表格,一种是您将人员数据放入数据库,另一种是允许您根据文档类型和文档编号进行搜索,我们将它们称为 Form1 和 Form2。问题是,当用户在表单 2 上按 OK 并且文档或文档类型为空时,一个 msgbox 会显示告诉他们填写文本框,但之后表单会关闭,所以我想要做的是防止表单关闭,如果用户按确定,任何字段为空。
我在 form2 上的 OK 按钮单击事件(我想阻止表单关闭):
Private Sub cmd_ok_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmd_ok.Click
If Me.txt_dni.Text = "" Then
MsgBox("Numero Documento vacio", vbOKOnly + vbCritical, "Atencion")
Me.txt_dni.Focus()
Exit Sub
End If
If Me.cmb_tdoc.SelectedIndex = -1 Then
MsgBox("Tipo de Documento vacio", vbOKOnly + vbCritical, "Atencion")
Me.cmb_tdoc.Focus()
Exit Sub
End If
End Sub
我将值从 Form2 获取到其父 form1;当我需要使用文档类型和文档编号在 datagridview 上查看某人时,我调用此函数:
私有函数 abrir_form2(ByRef rdoc2 As Integer, ByRef rtdoc2 As Integer)
暗淡对话框 As Form2
将 doc2 调暗为整数
将 tdoc2 调暗为整数
dialog = New Form2()
Dim result As DialogResult = dialog.ShowDialog(Me)
doc2 = dialog.doc2
tdoc2 = dialog.tdoc2
rdoc2 = doc2
rtdoc2 = tdoc2
Return vbNull
End Function
两种形式:http: //i.imgur.com/n1EwfiW.png
也许还有另一种方法?还有其他方法可以解决这个问题吗?
提前致谢!