|
-
Feb 5th, 2003, 01:22 AM
#1
Thread Starter
New Member
Control form from another form
How can we control another form from another form? I mean we control form A from from B. For example, if we click button OK on form A, the action will occur on form B.
-
Feb 5th, 2003, 03:24 AM
#2
Fanatic Member
Gabriell
You can refer to controls in formB from formA as follows:
VB Code:
' cmdUpdate event is in form A
private sub cmdUpdate_Click()
frmFormB.txtCustid.Text = 123
End Sub
I personally don't like this technique of explicitly refering to a control on another form. You can alternatively add a public method in Form B and then invoke that method from form A
VB Code:
' Code in form B
Public sub UpdateCustomerID(byval custid as string)
txtCustid.Text = custid
End sub
' code in form A
' cmdUpdate event is in form A
private sub cmdUpdate_Click()
frmFormB.UpdateCustomerID("123")
End Sub
Using VB.NET 2003/.NET 1.1/C# 2.0
http://del.icio.us/rajoo
Blow your mind, smoke gunpowder
Ashes to ashes, dust to dust
If God won't have you, the devil will. - Author unknown
Don't follow me, I'm lost too ...
-
Feb 7th, 2003, 03:53 AM
#3
Registered User
Send a instance of the first form to the second form when its opened. To do that rewrite the constructor of the second form to take a form as an argument. Something like this...
Code:
Dim baseForm as Form1
Public Sub New(frm as Form)
baseform = frm
InitializeComponent()
End Sub
Then you have a reference to the form.
-
Feb 7th, 2003, 07:01 AM
#4
Sleep mode
Re: Control form from another form
Originally posted by Gabriell
How can we control another form from another form? I mean we control form A from from B. For example, if we click button OK on form A, the action will occur on form B.
or you could declare instances of your forms in a module as follow:
VB Code:
'in a module
dim frm1 as new form1
dim frm2 as new form2
'in a form :
frm2.button1.name ="blah"
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|