PageRenderTime 12ms CodeModel.GetById 2ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 1ms

/Visual Studio 2008/VBWinFormPassValueBetweenForms/Form1.vb

#
Visual Basic | 48 lines | 17 code | 4 blank | 27 comment | 0 complexity | e2bb224334d01204bdce46d0a9d324b3 MD5 | raw file
 1'************************************* Module Header **************************************\
 2' Module Name:  Form1.vb
 3' Project:      VBWinFormPassValueBetweenForms
 4' Copyright (c) Microsoft Corporation.
 5' 
 6' This sample demonstrates how to pass value between forms.
 7'  
 8' There're two common ways to pass value between forms:
 9' 
10' 1. Use a property.
11'    Create a public property on the target form class, then we can pass value to the target 
12'    form by setting value for the property.
13' 
14' 2. Use a method.
15'    Create a public method on the target form class, then we can pass value to the target 
16'    form by passing the value as parameter to the method.
17' 
18' This source is subject to the Microsoft Public License.
19' See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL.
20' All other rights reserved.
21' 
22' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
23' EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
24' WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
25'******************************************************************************************/
26
27Public Class Form1
28    Inherits Form
29
30    Public Sub New()
31        MyBase.New()
32        InitializeComponent()
33    End Sub
34
35    Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
36        ' Method 1 - Use A Property
37        Dim f2 As Form2 = New Form2
38        f2.ValueToPassBetweenForms = Me.TextBox1.Text
39        f2.ShowDialog()
40    End Sub
41
42    Private Sub button2_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button2.Click
43        ' Method 2 - Use A Method
44        Dim f2 As Form2 = New Form2
45        f2.SetValueFromAnotherForm(Me.TextBox1.Text)
46        f2.ShowDialog()
47    End Sub
48End Class