By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,573 Members | 1,845 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,573 IT Pros & Developers. It's quick & easy.

accessing / setting properties

P: n/a
Hi,
how can I access / set properties of controls in other forms.
i.e. mdi parent of mdi child
mdi child of mdi child
mdi child of mdi parent

Thanks
Alex

Nov 20 '05 #1
Share this Question
Share on Google+
11 Replies


P: n/a
Hi Alex,

You need to have a reference to the other Form.

Each child has an MdiParent property which is nice and straightforward.
The parent Form has an MdiChildren collection which you'll have to rummage
in to find a specific child Form.

Regards,
Fergus
Nov 20 '05 #2

P: n/a
Fergus,
hmm... I have a status bar in the MdiParent and from the child calling
Me.MdiParent.stBar.Text = "some text" gives me the error

stBar is not a member of System.Windows.Forms.Form.

What am I doing wrong ?

Thanks
Alex
Fergus Cooney wrote:
Hi Alex,

You need to have a reference to the other Form.

Each child has an MdiParent property which is nice and straightforward.
The parent Form has an MdiChildren collection which you'll have to rummage
in to find a specific child Form.

Regards,
Fergus


Nov 20 '05 #3

P: n/a
"alex" <ai******@hotmail.com> schrieb
Fergus,
hmm... I have a status bar in the MdiParent and from the child
calling Me.MdiParent.stBar.Text = "some text" gives me the error

stBar is not a member of System.Windows.Forms.Form.

What am I doing wrong ?


The type of Me.MdiParent is System.Windows.Forms.Form. stBar is not a member
of the Form class. If the type of the child will always be the same, you
can use type casting:

Directcast(Me.MdiParent, <type name of the container>).stBar.Text = "some
text"
IMHO, the better approach is to raise an event in the child and catch it in
the MdiParent. In the event handler the parent sets the text of the statusbar.
--
Armin

Nov 20 '05 #4

P: n/a
alex <ai******@hotmail.com> wrote in news:3F**************@hotmail.com:
Fergus,
hmm... I have a status bar in the MdiParent and from the child calling
Me.MdiParent.stBar.Text = "some text" gives me the error

stBar is not a member of System.Windows.Forms.Form.


Make sure that stBar is either a property in your form class, or make the
variable public.

Chris
Nov 20 '05 #5

P: n/a
Hi Alex,

Ah yes, thanks for reminding me.

Me.MdiParent <will> give you correct parent Form but the Type of MdiParent
is plain old Form, whereas the actual Form is a derivation -
AlexesWonderfulAppForm, so the Controls are 'hidden'.

You'll need to cast the MdiParent to get at the additional properties.
Dim MyMainMan As AlexesWonderfulAppForm
MyMainMan = DirectCast (Me.MdiParent, AlexesWonderfulAppForm)
MyMainMan.stBar.Text = "Yo, Dude!!"

You can, of course, do all that in one go:
DirectCast (Me.MdiParent, AlexesWonderfulAppForm).stBar.Text _
= "Yo, Dude!!"

Regards,
Fergus

Nov 20 '05 #6

P: n/a
All,
Thanks for the help. problem is solved

A

Nov 20 '05 #7

P: n/a
Cor
Hi Chris,
I have seen a lot of Fergus code, but making a variable just public,
somewhere alone on the top of his program.
I don't believe he likes that.
;-)
Cor
Nov 20 '05 #8

P: n/a
Hi Cor, Chris

'Tis true, although I'll do it for expediency in some cases. ;-) I'll even
suggest it in an answer, if I think that the OP is inexperienced and would
reject the 'better' approach as being too complicated, or if I think that
expediency is their priority.

However, in this case the StatusBar is Friend which is visibility enough.
The problem is that MdiParent Property is of Type Form and doesn't have the
StatusBar.

Regards,
Fergus
Nov 20 '05 #9

P: n/a
Fergus,
as you seem to be the expert here :-) , how can I access the status bar
from a class that is called by a mdi child. i have implemented a class
that reads a file and i want to update the status bar from within that
class.

the direc cast me.mdiparent does not work ...

Thanks
Sorry , question might obvious... just started in vb.

Alex

Fergus Cooney wrote:
Hi Alex,

Ah yes, thanks for reminding me.

Me.MdiParent <will> give you correct parent Form but the Type of MdiParent
is plain old Form, whereas the actual Form is a derivation -
AlexesWonderfulAppForm, so the Controls are 'hidden'.

You'll need to cast the MdiParent to get at the additional properties.
Dim MyMainMan As AlexesWonderfulAppForm
MyMainMan = DirectCast (Me.MdiParent, AlexesWonderfulAppForm)
MyMainMan.stBar.Text = "Yo, Dude!!"

You can, of course, do all that in one go:
DirectCast (Me.MdiParent, AlexesWonderfulAppForm).stBar.Text _
= "Yo, Dude!!"

Regards,
Fergus


Nov 20 '05 #10

P: n/a
"Cor" <no*@non.com> wrote in news:3f8567c9$0$32189$48b97d01
@reader22.wxs.nl:
Hi Chris,
I have seen a lot of Fergus code, but making a variable just public,
somewhere alone on the top of his program.
I don't believe he likes that.


I agree with him but it was a quick, off the top of my head, answer.

Chris
Nov 20 '05 #11

P: n/a
Hi Alex,

:-) Flattery will get you everywhere, lol - except when I'm out for the
day!

|| the direc cast me.mdiparent does not work ...

Is that the one where the child is accessing the parent's StatusBar, ('cos
that works for me) or do you mean that using the same method with a different
class doesn't work?

If it's the first one, I'll need some code to see what's different between
what I've got here and what you've got.

Moving on...

If you have a separate class (I'll call it AlexFileReader) that needs to
use the StatusBar to display progress, the class needs a reference to it, or
to it's owner.

The simplest way, given that you're new to VB would be to tell the class
which StatusBar to play with. It depends where your AlexFileReader is created.
If the parent Form does this then it is very simple

In Main Form
Dim oAlexFileReader As AlexFileReader
oAlexFileReader = New AlexFileReader (Me.stBar)

In AlexFileReader
Private oStatusBar As StatusBar
Sub New (oThisStatusBar As StatusBar)
oStatusBar = oThisStatusBar
End Sub
Sub ShowProgress
oStatusBar.Text = "It's going great!!"
End Sub

If you are creating the AlexFileReader from an child Form, then you need
the full-typed reference to the main Form that we talked about earlier.

In Child Form
Dim MyMainMan As AlexesWonderfulAppForm
MyMainMan = DirectCast (Me.MdiParent, AlexesWonderfulAppForm)

Dim oAlexFileReader As AlexFileReader
oAlexFileReader = New AlexFileReader (MyMainMan.stBar)

If you are creating the AlexFileReader from a different class altogether,
then a bit more is needed. But I'm assuming that you aren't. ;-)

Regards,
Fergus
Nov 20 '05 #12

This discussion thread is closed

Replies have been disabled for this discussion.