PageRenderTime 7ms CodeModel.GetById 1ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/Visual Studio 2008/VBWinFormPassValueBetweenForms/Form2.vb

#
Visual Basic | 58 lines | 23 code | 10 blank | 25 comment | 0 complexity | 4b3924818e0f33c3eba97ffd5b4fb5f3 MD5 | raw file
 1'************************************* Module Header **************************************\
 2' Module Name:  Form2.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 Form2
28    Inherits Form
29
30    Public Sub New()
31        MyBase.New()
32        InitializeComponent()
33
34        AddHandler Load, AddressOf Me.FrmPassValueBetweenForms2_Load
35
36    End Sub
37
38    Private Sub FrmPassValueBetweenForms2_Load(ByVal sender As Object, ByVal e As EventArgs)
39        Me.lbDisplay.Text = Me._valueToPassBetweenForms
40    End Sub
41
42    Private _valueToPassBetweenForms As String
43
44    Public Property ValueToPassBetweenForms() As String
45        Get
46            Return Me._valueToPassBetweenForms
47        End Get
48        Set(ByVal value As String)
49            Me._valueToPassBetweenForms = value
50        End Set
51    End Property
52
53
54    Public Sub SetValueFromAnotherForm(ByVal val As String)
55        Me._valueToPassBetweenForms = val
56    End Sub
57
58End Class