Form Concepts CodeSample - Storing and retrieving values from dialog forms

From Visual WebGui Wiki

Jump to: navigation, search


Contents

Overview

This article is a part of Form Concepts series of articles.

This codesample shows how you can store values within the Dialog Form and later retrieve that value in the registered Closed event handler in the caller.

Another, but very similar CodeSample can be found at Storing and retrieving new values from dialog forms. The difference between the two samples being that this one stores the necessary values in the dialog form, only to retrieve it later, while the other sample changes or adds values which are then accessible by the MainForm.

VB.NET Code

Setting up and calling the dialog form

We will be storing starttime within the dialog form.

Dim f As SlaveForm = New SlaveForm
f.Start = DateTime.Now()
AddHandler f.Closed, AddressOf DialogFormHandler
f.ShowDialog()
 
Private Sub DialogFormHandler(ByVal sender As Object, ByVal e As EventArgs)
    Dim dForm As SlaveForm = sender
    If dForm.DialogResult = Gizmox.WebGui.Forms.DialogResult.OK Then
        Dim seconds = DateDiff(DateInterval.Second, dForm.Start, DateTime.Now())
        MessageBox.Show("OK was chosen - after " + seconds.ToString() + " seconds")
    Else
        MessageBox.Show("Cancal was chosen")
    End If
End Sub

The dialog form's code:

Friend Start As DateTime
 
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