473,386 Members | 1,799 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Controlling MDI toolbars when child forms close

Help! Another newbie question I'm afraid. I have a toolbar on an MDI form,
which I can control OK to produce a child form. When the child form is
active, the appropriate MDI parent form toolbar button properties are set as
follows: .pushed=true and .enabled=false.

My problem is how do I set the reverse conditions when I close this child
form? I have tried putting (in the Exit button click event)
Toolbar1.Buttons(6).Pushed=False
Toolbar1.Buttons(6).Enabled=True
but get a syntax error saying that 'name Toolbar1 is not declared.'

and even
MDIParentFormname.Toolbar1.Buttons(6).Pushed=False
MDIParentFormname.Toolbar1.Buttons(6).Enabled=True
gives me a syntax error 'Reference to a non-shared member requires an object
fererence'.

How and where can I refer to the parent form toolbar within the child so
that I can change its properties? Many thanks for any help/advice given.
Nov 21 '05 #1
4 2750
LCAdeveloper wrote:
My problem is how do I set the reverse conditions when I close this
child form?
You need a reference to the actual instance of your MDI parent form...
I have tried putting (in the Exit button click event)
Toolbar1.Buttons(6).Pushed=False
Toolbar1.Buttons(6).Enabled=True
but get a syntax error saying that 'name Toolbar1 is not declared.'
I assume this code is within the MDI child form itself. This isn't working
because it's stating that the Toolbar1 control is within the child form,
which isn't the case. That's why it says it can't find a declaration for the
toolbar.
and even
MDIParentFormname.Toolbar1.Buttons(6).Pushed=False
MDIParentFormname.Toolbar1.Buttons(6).Enabled=True
gives me a syntax error 'Reference to a non-shared member requires an
object fererence'.


This isn't working because MDIParentFormname is a class (i.e., a description
of the MDI Parent form) rather than an object (an actual instance of the MDI
Parent form).

The easiest way to get a reference to the actual MDI Parent form object is
to use the MDIParent property of your child form. This must have been set in
order for your MDI child form to be appearing within the MDI container. So
for example, in the Closing or Closed event of your child form, try the
following code:

\\\
Me.MDIParent.Toolbar1.Buttons(6).Pushed = False
Me.MDIParent.Toolbar1.Buttons(6).Enabled = True
///

Hopefully that will do the job.

--

(O) e n o n e
Nov 21 '05 #2
Thanks for your reply. Please forgive my ignorance, but pasting the suggested
code into my closing statement produces a syntax error in that
'Me.MdiParent.Toolbar1' is not a member of 'System.Windows.Forms.Form'.

My orginal MDI container form, let us call this MDIParent Form1, produces a
child form with the following code when a menu item is activated:
\\\
Dim NewMDIChild As New Form2
Toolbar1.Buttons(6).Pushed = True
NewMDIChild.MdiParent = Me
NewMDIChild.Show
///

I take it that this means that Form2 is an MDIChild of Form1? I'm confused
now. Do I have to declare an instance of the toolbar in the child form in
able to access it, or am I missing something more fundamental in how Toolbar1
is created? Many thanks indeed if you can help me further: I'm finding the
change from VB4 to VB.NET2003 quite a steep learning curve. :-(

"Oenone" wrote:
LCAdeveloper wrote:
My problem is how do I set the reverse conditions when I close this
child form?


You need a reference to the actual instance of your MDI parent form...
I have tried putting (in the Exit button click event)
Toolbar1.Buttons(6).Pushed=False
Toolbar1.Buttons(6).Enabled=True
but get a syntax error saying that 'name Toolbar1 is not declared.'


I assume this code is within the MDI child form itself. This isn't working
because it's stating that the Toolbar1 control is within the child form,
which isn't the case. That's why it says it can't find a declaration for the
toolbar.
and even
MDIParentFormname.Toolbar1.Buttons(6).Pushed=False
MDIParentFormname.Toolbar1.Buttons(6).Enabled=True
gives me a syntax error 'Reference to a non-shared member requires an
object fererence'.


This isn't working because MDIParentFormname is a class (i.e., a description
of the MDI Parent form) rather than an object (an actual instance of the MDI
Parent form).

The easiest way to get a reference to the actual MDI Parent form object is
to use the MDIParent property of your child form. This must have been set in
order for your MDI child form to be appearing within the MDI container. So
for example, in the Closing or Closed event of your child form, try the
following code:

\\\
Me.MDIParent.Toolbar1.Buttons(6).Pushed = False
Me.MDIParent.Toolbar1.Buttons(6).Enabled = True
///

Hopefully that will do the job.

--

(O) e n o n e

Nov 21 '05 #3
LCAdeveloper wrote:
Thanks for your reply. Please forgive my ignorance, but pasting the
suggested code into my closing statement produces a syntax error in
that 'Me.MdiParent.Toolbar1' is not a member of
'System.Windows.Forms.Form'.
Ah, my bad. Try this in your child form's Closing event (I've actually
tested it this time so it really should work):

\\\
Dim myMDI as Form1
myMDI = DirectCast(Me.MdiParent, Form1)
myMDI.Toolbar1.Buttons(6).Pushed = False
myMDI.Toolbar1.Buttons(6).Enabled = True
///

The first line declares a new object pointer whose type is Form1 (i.e., the
same type as your MDI parent form). It doesn't create an new object, just a
pointer to an object (which currently points to Nothing).

The second line points the myMDI variable at your MDI parent form, which it
accesses through the child form's MdiParent property. If you have Option
Strict On, this will fail with a compilation error, however, so you use
DirectCast to tell VB that MDIParent actually is of type Form1. (If
MdiParent were of a different type, this would give you a run-time error
when it executed, but as you know it will always be a Form1 object this is
ok). myMDI now points to the actual instance of Form1 that is the MDI
parent.

Now you have access to the MDI parent instance, you can access its members,
such as Toolbar1. This will then allow you to perform the updates that you
need.

Try that and see how you get on this time.
My orginal MDI container form, let us call this MDIParent Form1,
produces a child form with the following code when a menu item is
activated:
\\\
Dim NewMDIChild As New Form2
Toolbar1.Buttons(6).Pushed = True
NewMDIChild.MdiParent = Me
NewMDIChild.Show
///

I take it that this means that Form2 is an MDIChild of Form1?
Form2 is a class the describes a form, not an actual instance of a form.
NewMDIChild is an instance of a form (i.e., a real form that exists on the
screen), and it is a child of Form1 (due to the fact that it's MdiParent
property has been set to your MDI parent).
I'm
confused now. Do I have to declare an instance of the toolbar in the
child form in able to access it, or am I missing something more
fundamental in how Toolbar1 is created?


The difference is that when the MDI parent form talks to Toolbar1 in the
code you posted above, it is talking within the context of itself. The code:

Toolbar1.Buttons(6).Pushed = True

....actually in full is this:

Me.Toolbar1.Buttons(6).Pushed = True

Because you omit the "Me.", VB looks for a Toolbar1 contained within the
current object. Because this is the MDI parent and it does contain Toolbar1,
everything works fine.

However, when you try to run the same code in your MDI child form, the child
form looks for a control called Toolbar1 within itself. There isn't one
there of course, because the toolbar is in the MDI parent form, not the MDI
child form.

The fix is therefore to gain access to the MDI parent form so that you can
tell it to update its toolbar. This is what the code I posted above is
doing.

Does that make it any clearer?

--

(O) e n o n e
Nov 21 '05 #4
Thank you very much indeed for your kind reply: your careful explanation has
made things a lot clearer for me - and the code worked too, of course! Many
thanks. :-D

"Oenone" wrote:
LCAdeveloper wrote:
Thanks for your reply. Please forgive my ignorance, but pasting the
suggested code into my closing statement produces a syntax error in
that 'Me.MdiParent.Toolbar1' is not a member of
'System.Windows.Forms.Form'.


Ah, my bad. Try this in your child form's Closing event (I've actually
tested it this time so it really should work):

\\\
Dim myMDI as Form1
myMDI = DirectCast(Me.MdiParent, Form1)
myMDI.Toolbar1.Buttons(6).Pushed = False
myMDI.Toolbar1.Buttons(6).Enabled = True
///

The first line declares a new object pointer whose type is Form1 (i.e., the
same type as your MDI parent form). It doesn't create an new object, just a
pointer to an object (which currently points to Nothing).

The second line points the myMDI variable at your MDI parent form, which it
accesses through the child form's MdiParent property. If you have Option
Strict On, this will fail with a compilation error, however, so you use
DirectCast to tell VB that MDIParent actually is of type Form1. (If
MdiParent were of a different type, this would give you a run-time error
when it executed, but as you know it will always be a Form1 object this is
ok). myMDI now points to the actual instance of Form1 that is the MDI
parent.

Now you have access to the MDI parent instance, you can access its members,
such as Toolbar1. This will then allow you to perform the updates that you
need.

Try that and see how you get on this time.
My orginal MDI container form, let us call this MDIParent Form1,
produces a child form with the following code when a menu item is
activated:
\\\
Dim NewMDIChild As New Form2
Toolbar1.Buttons(6).Pushed = True
NewMDIChild.MdiParent = Me
NewMDIChild.Show
///

I take it that this means that Form2 is an MDIChild of Form1?


Form2 is a class the describes a form, not an actual instance of a form.
NewMDIChild is an instance of a form (i.e., a real form that exists on the
screen), and it is a child of Form1 (due to the fact that it's MdiParent
property has been set to your MDI parent).
I'm
confused now. Do I have to declare an instance of the toolbar in the
child form in able to access it, or am I missing something more
fundamental in how Toolbar1 is created?


The difference is that when the MDI parent form talks to Toolbar1 in the
code you posted above, it is talking within the context of itself. The code:

Toolbar1.Buttons(6).Pushed = True

....actually in full is this:

Me.Toolbar1.Buttons(6).Pushed = True

Because you omit the "Me.", VB looks for a Toolbar1 contained within the
current object. Because this is the MDI parent and it does contain Toolbar1,
everything works fine.

However, when you try to run the same code in your MDI child form, the child
form looks for a control called Toolbar1 within itself. There isn't one
there of course, because the toolbar is in the MDI parent form, not the MDI
child form.

The fix is therefore to gain access to the MDI parent form so that you can
tell it to update its toolbar. This is what the code I posted above is
doing.

Does that make it any clearer?

--

(O) e n o n e

Nov 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
by: Albretch | last post by:
Hi, client wants for a window with no toolbars to open (technical and 'esthetical' reasons) after the window, user clicks on, is being closed. I told them about security settings in browsers...
1
by: MacDermott | last post by:
I have an MDB file which is secured using a custom MDW file. I'd like to have most users see only the shortened menu you see when you set the Startup option "Allow full menus" to False. But...
2
by: Guy Babbitt | last post by:
I have an MDI application that starts an instance of a child form at application start. I have an event handler on a combo box checking for the selected value to change. When the select value...
3
by: Steve Barnett | last post by:
I developed an app using VC# Express Beta that included an mdi parent and an mdi child form. Both forms contain a ToolStrip and, while using the Beta, these ToolStrips merged together as I expected...
8
by: al | last post by:
Greetings, If I instansiate child forms in MDI parent, what is the way to close them. I can't find an event related to child to do such task. I want to close 3 child forms, all in the same...
8
by: Edwinah63 | last post by:
Hi Everyone, in vb6 i was able to execute the following code and it would close the children is the reverse order they were opened eg the last child opened was the first child to close. in...
0
by: Tom | last post by:
Let's say I have an MDI parent that has 5 open child windows in it. Now let's say that I have a function in the MDI parent that attempts to close all the child windows. It's starts running, closing...
3
by: Simon Verona | last post by:
I have a parent form which contains a toolbar. The toolbar controls the loading and switching to of MDI child forms. The code for the toolbar click event and one of the subroutines that loads...
13
by: Academic | last post by:
I have a MDI form, sometimes child forms and sometimes forms that are neither If I close the app the child forms closing and closed event happens followed by the Mdi form receiving the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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...

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.