PC Review


Reply
Thread Tools Rate Thread

accessing / setting properties

 
 
alex
Guest
Posts: n/a
 
      9th Oct 2003
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

 
Reply With Quote
 
 
 
 
Fergus Cooney
Guest
Posts: n/a
 
      9th Oct 2003
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


 
Reply With Quote
 
alex
Guest
Posts: n/a
 
      9th Oct 2003
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
>
>


 
Reply With Quote
 
Armin Zingler
Guest
Posts: n/a
 
      9th Oct 2003
"alex" <(E-Mail Removed)> 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

 
Reply With Quote
 
Fergus Cooney
Guest
Posts: n/a
 
      9th Oct 2003
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



 
Reply With Quote
 
Chris Dunaway
Guest
Posts: n/a
 
      9th Oct 2003
alex <(E-Mail Removed)> wrote in news:(E-Mail Removed):

> 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
 
Reply With Quote
 
alex
Guest
Posts: n/a
 
      9th Oct 2003
All,
Thanks for the help. problem is solved

A

 
Reply With Quote
 
Cor
Guest
Posts: n/a
 
      9th Oct 2003
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


 
Reply With Quote
 
Fergus Cooney
Guest
Posts: n/a
 
      9th Oct 2003
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


 
Reply With Quote
 
alex
Guest
Posts: n/a
 
      9th Oct 2003
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
>
>
>


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Accessing Properties? Shak Microsoft Dot NET 4 19th Oct 2006 11:33 PM
Accessing all the properties of IIS =?Utf-8?B?R2F1dGFtS3VtYXI=?= Microsoft C# .NET 1 16th Oct 2005 11:47 AM
Accessing/Setting Custom Properties in a Custom TreeNode Bishop Microsoft VB .NET 0 29th Sep 2005 03:12 AM
setting properties via properties window during runtime Herfried K. Wagner [MVP] Microsoft VB .NET 2 1st Jun 2005 05:17 AM
Accessing Properties Prateek Microsoft VB .NET 2 9th Oct 2003 01:19 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:11 PM.