Results 1 to 10 of 10

Thread: [RESOLVED] Form sharing problem

Threaded View

  1. #7
    Frenzied Member mar_zim's Avatar
    Join Date
    Feb 2004
    Location
    Toledo Cebu City.
    Posts
    1,416

    Re: Form sharing problem

    if you want to get the value of the property in form2 then make the property as public shared.
    like this one
    VB Code:
    1. 'in your form2
    2. Shared s As String
    3.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    4.         mystring() = TextBox1.Text
    5.         Dim f As New Form1()
    6.         f.ShowDialog()
    7.     End Sub
    8.  
    9.     Public Shared Property mystring() As String
    10.         Get
    11.             Return s
    12.         End Get
    13.         Set(ByVal Value As String)
    14.             s = Value
    15.         End Set
    16.     End Property
    17. 'in form1
    18. 'no need to instantiate the form2
    19.  Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    20.         MessageBox.Show(Form2.mystring())
    21.     End Sub
    edit: no need to put public in shared property because in vb.net shared methodd by default is public where as in c# static methods cannot be accessed outside of the class if it's not declared public.
    Last edited by mar_zim; Jul 29th, 2005 at 03:57 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width