473,473 Members | 1,862 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

accessing / setting properties

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
11 1337
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
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
"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
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
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
All,
Thanks for the help. problem is solved

A

Nov 20 '05 #7
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
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
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
"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Serge calderara | last post by:
Dear all, Does any one have a ready class that is able to access a configuration file and make different type of querry, read, write operation? Why re invanting the real if something already...
1
by: Toufani | last post by:
Hi everybody, I want to retrieve information about objects in active directory windows 2000 and their properties. I got some codes that don't work absolutely. for example I can't retrieve users...
18
by: Dixie | last post by:
Can I set the Format property in a date/time field in code? Can I set the Input Mask in a date/time field in code? Can I set the Format of a Yes/No field to Checkbox in code? I am working on...
3
by: Craig G | last post by:
i have a user control which is basically a datagrid, which has add/edit/delete buttons on the grid is there anyway of accessing the actual datagrid from the form itself? basically i want to...
0
by: Joergen Bech | last post by:
Fairly new to ASP.NET 1.1. Getting the error below when running application on a web server outside of my control, but only the first time I run it: 1. After a long period of inactivity (or...
0
by: Bishop | last post by:
I've figured out how to create a custom TreeNode with custom properties and I can view those properties at runtime, but I'm not sure how to change them after I've added the custom node to the tree....
4
by: Shak | last post by:
Hi My code looks like the follwing: namespace A.B.C { .... private void foo() { A.B.C.Properties.Settings.Default.Save();
4
by: glen | last post by:
I have a multiproject solution; one of the projects is a group of classes doing data massage and insertions. One of the other projects is a UI that kicks off the process in certain situations. I'd...
3
by: Beorne | last post by:
In the classes I develop my attributes are always private and are exposed using properties. directly or to access the attributes using the properties? Does "wrapper" setter/getter properties...
0
by: porksmash | last post by:
I'm developing an app here that uses ActiveX controls to connect to industrial cameras over Ethernet. I want to be able to dynamically create those controls at runtime based on how many cameras are...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.