variables and controls across forms

  • Thread starter Thread starter Sameh Ahmed
  • Start date Start date
S

Sameh Ahmed

Hello there
I need to know how can I deal with a variable or control on a form different
than the one I am currently working on.
Ie. I want to change a lable on a form from a button on another, i also want
to be able to read and write vaules to public variables on the other form.
How can i do that?
Thanks in advance
Regards
 
Hello,

I would create public properties in the other form, this way if things
change on the other form, you have far less code to change.

E.g.

Public WriteOnly Property SetLabel() As String
Set(ByVal Value As String)
lblExample.Text = Value
End Set
End Property

The calling form would then do the following:

OtherForm.SetLabel("Hello World")

Regards
Simon Jefferies
Tools Programmer
Headfirst Productions
(e-mail address removed)
 
* "Sameh Ahmed said:
I need to know how can I deal with a variable or control on a form different
than the one I am currently working on.
Ie. I want to change a lable on a form from a button on another, i also want
to be able to read and write vaules to public variables on the other form.
How can i do that?

The code below shows you how to do that with a textbox control. You can
adapt it for your needs easily.

In the 2nd form:

\\\
Private m_t As TextBox

Public Sub New(ByVal ResultTextBox As TextBox)
MyBase.New()
m_t = ResultTextBox
InitializeComponent()
End Sub

' You can access the control with m_t.
///


Main form:

\\\
Dim f As New Form1(Me.TextBox1)
f.Show()
///
 
Back
Top