PageRenderTime 38ms CodeModel.GetById 10ms RepoModel.GetById 1ms app.codeStats 0ms

/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. Public Class Form1
  27. Inherits Form
  28. Public Sub New()
  29. MyBase.New()
  30. InitializeComponent()
  31. End Sub
  32. Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
  33. ' Method 1 - Use A Property
  34. Dim f2 As Form2 = New Form2
  35. f2.ValueToPassBetweenForms = Me.TextBox1.Text
  36. f2.ShowDialog()
  37. End Sub
  38. Private Sub button2_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button2.Click
  39. ' Method 2 - Use A Method
  40. Dim f2 As Form2 = New Form2
  41. f2.SetValueFromAnotherForm(Me.TextBox1.Text)
  42. f2.ShowDialog()
  43. End Sub
  44. End Class