|
-
May 9th, 2003, 04:20 AM
#1
Access controls from another form (mdi)
I have a main form that has a Statusbar control on it. I am then opening several child forms within this main form.
How do i access the Statusbar control from within these child forms? any ideas?
-
May 9th, 2003, 06:58 AM
#2
You will need to pass the reference of your main form to the child forms. Then a child form can refer any controls on the main form through that reference.
-Cool Bizs
-
May 9th, 2003, 06:59 AM
#3
am just getting to grips with vb.net so not really sure how to do that.
can you give me any pointers?
-
May 9th, 2003, 10:53 AM
#4
There are few ways to do this. Here is one.
Lets say your main FORM class name is FMain and your child FORM class is called FChild. Then consider the following:
Code:
' your main FORM
public class FMain
...
' when you add a control the declaration should look like this
friend withevents txtUsername as textbox
...
' show the child
private sub showchild()
dim myChild as new FChild()
myChild.ParentForm = me
....
end sub
...
end class
' your child FORM
public class FChild
...
' var to hold the parent
public ParentForm as FMain = Nothing
...
' access the textbox in main form
private sub DummyProc()
if (not m_MainForm is nothing) then m_MainForm.txtUsername.Text = "From CHILD class."
end sub
...
end class
Again, you have so many ways depending on how you instantiate the child form. The basic idea is to have a reference to the parent object so that you can access any exposed members (declared with either PUBLIC or FRIEND).
//EDIT: variable name in child form was corrected.
-Cool Bizs
Last edited by coolbiz; May 9th, 2003 at 10:57 AM.
-
May 9th, 2003, 10:54 AM
#5
-
June 26th, 2003, 08:03 PM
#6
follow up question...()
my apology for using your thread sir tonyf 
Sir CoolBiz, How about using the MDIParent as one of the property the child form instead of making an instance ParentForm in the child form? Is it possible?
Thanks...
"ninja ray makapatay ninjo..mga limbarok mong dako" --
in english...-->
" If you wish to make an improved product, you must already be engaged in making an inferior one. "
-
June 27th, 2003, 06:27 AM
#7
You're probably right. If MDI child form exposes a variable MDIParent, that should also point to the parent form. Try it out and post the relsult 
-Cool Bizs
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
|