Form Concepts CodeSample - Returning responses from dialog forms
From Visual WebGui Wiki
| This article will have a few sections added to it soon, based on the following article type skeleton: NewCodeSampleTemplate |
Contents |
Overview
This article is a part of Form Concepts series of articles.
The samplecode will show how you can create a dialog form an retrieve responses via the DialogResult property and registering a handler for the Closed event. This is the exact same method as you use for the MessageBox builtin dialogform class as you can see in the codesample on using the MessageBox control.
VB.NET Code
Setting up and calling the dialog form
Dim f As SlaveForm = New SlaveForm AddHandler f.Closed, AddressOf DialogFormHandler f.ShowDialog() Private Sub DialogFormHandler(ByVal sender As Object, ByVal e As EventArgs) Dim dForm As Form = sender If dForm.DialogResult = Gizmox.WebGui.Forms.DialogResult.OK Then MessageBox.Show("OK was chosen") Else MessageBox.Show("Cancal was chosen") End If End Sub
The dialog form's code
Note that setting the DialogResult in the Load event will give you a Cancel response even if you close the form without using the buttons.
Private Sub SlaveForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.DialogResult = Gizmox.WebGui.Forms.DialogResult.Cancel End Sub Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click Me.DialogResult = Gizmox.WebGui.Forms.DialogResult.OK Me.Close() End Sub Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click Me.DialogResult = Gizmox.WebGui.Forms.DialogResult.Cancel Me.Close() End Sub
C# Code
| The conversion of this code to C# has not been completed yet. Please feel free to contribute and add contents to the Wiki |
