Form Concepts CodeSample - Returning responses from dialog forms

From Visual WebGui Wiki

Jump to: navigation, search


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

Personal tools