- 1 year ago
Is there a Universal Modal Form?, VB .net framework windows forms
Comment
1 / 1
Yes, there are ways to create a universal modal form in VB .NET Framework Windows Forms. One way is to create a custom form that can be used as a modal dialog box in different parts of your application. Here's a sample code that you can use as a starting point:
vb.netPublic Class UniversalModalForm
Private Sub btnOK_Click(sender As Object, e As EventArgs) Handles btnOK.Click
' Perform validation and save data
Me.DialogResult = DialogResult.OK
End Sub
Private Sub btnCancel_Click(sender As Object, e As EventArgs) Handles btnCancel.Click
Me.DialogResult = DialogResult.Cancel
End Sub
End Class
You can customize this form by adding controls and validation logic as needed. To use this form as a modal dialog box, you can create an instance of it and call the ShowDialog
method:
vb.netDim myForm As New UniversalModalForm()
Dim dialogResult As DialogResult = myForm.ShowDialog()
If dialogResult = DialogResult.OK Then
' Handle OK button click
ElseIf dialogResult = DialogResult.Cancel Then
' Handle Cancel button click
End If
You can also pass data between the parent form and the modal form by setting public properties or using events.