473,581 Members | 2,567 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do I access a "sibling" form?

I have a MDI Parent Child set of forms
FormContainer --MDIParent
FormStart --MDIChild
FormMain-->MDIChild
FormSliceInfo-->MDIChild

I use the following in the beginning of FomrContainer

Public Class FormContainer
Inherits System.Windows. Forms.Form
Dim frmStart As New FormStart
Dim frmMain As New FormMain
Dim frmSliceInfo As New FormSliceInfo

and so on.

Now when I am in the frmMain, I have a button that I want to use, to access
frmSliceInfo. How do I do that? I am able to access it from the Main Menu,
because it is under the FormContainer, but not from frmMain. In frmMain, I
tried Me.MDIParent.fr mSliceInfo but that did not work.

Thanx for your help.
--
Anil Gupte
www.keeninc.net
www.icinema.com
Sep 5 '07 #1
9 2378
Create a module with Public object variables that are named for your forms.

Module1
Public Form1 as Form
public Form2 as Form
End Module

As you instantiate each form, assign the module object variable for that
form accordingly. You then have a reference to each form throughout your
application.

Sep 5 '07 #2
Anil,

Like controls are in a mdi forms all mdi forms in a collection in your
Parent form, you can just go through it to find the right one.

http://msdn2.microsoft.com/en-us/lib...en(vs.71).aspx

Cor
"Anil Gupte" <an*******@icin ema.comschreef in bericht
news:%2******** ********@TK2MSF TNGP05.phx.gbl. ..
>I have a MDI Parent Child set of forms
FormContainer --MDIParent
FormStart --MDIChild
FormMain-->MDIChild
FormSliceInfo-->MDIChild

I use the following in the beginning of FomrContainer

Public Class FormContainer
Inherits System.Windows. Forms.Form
Dim frmStart As New FormStart
Dim frmMain As New FormMain
Dim frmSliceInfo As New FormSliceInfo

and so on.

Now when I am in the frmMain, I have a button that I want to use, to
access frmSliceInfo. How do I do that? I am able to access it from the
Main Menu, because it is under the FormContainer, but not from frmMain.
In frmMain, I tried Me.MDIParent.fr mSliceInfo but that did not work.

Thanx for your help.
--
Anil Gupte
www.keeninc.net
www.icinema.com

Sep 5 '07 #3
I like this approach - although does it use more memory to declare these
forms
Public? Also, I have never used Modules? Where and how do you use them?
Is
there a tutorial somewhere on the web?

Thanx,
--
Anil Gupte
www.keeninc.net
www.icinema.com

"Charlie" <cfarrier at charlesfarriers oftware.comwrot e in message
news:AA******** *************** ***********@mic rosoft.com...
Create a module with Public object variables that are named for your
forms.

Module1
Public Form1 as Form
public Form2 as Form
End Module

As you instantiate each form, assign the module object variable for that
form accordingly. You then have a reference to each form throughout your
application.

Sep 5 '07 #4
I figured out how to do it thanx to your pointers, but it seems like quite a
hack. I thought some thing like this would work:

Public Class FormContainer
Inherits System.Windows. Forms.Form
Dim frmStart As New FormStart
Dim frmMain As New FormMain
Public frmSliceInfo As New FormSliceInfo

i.e. make the form a Public object.
--
Anil Gupte
www.keeninc.net
www.icinema.com

"Cor Ligthert [MVP]" <no************ @planet.nlwrote in message
news:eU******** ********@TK2MSF TNGP03.phx.gbl. ..
Anil,

Like controls are in a mdi forms all mdi forms in a collection in your
Parent form, you can just go through it to find the right one.

http://msdn2.microsoft.com/en-us/lib...en(vs.71).aspx

Cor
"Anil Gupte" <an*******@icin ema.comschreef in bericht
news:%2******** ********@TK2MSF TNGP05.phx.gbl. ..
>>I have a MDI Parent Child set of forms
FormContainer --MDIParent
FormStart --MDIChild
FormMain-->MDIChild
FormSliceInfo-->MDIChild

I use the following in the beginning of FomrContainer

Public Class FormContainer
Inherits System.Windows. Forms.Form
Dim frmStart As New FormStart
Dim frmMain As New FormMain
Dim frmSliceInfo As New FormSliceInfo

and so on.

Now when I am in the frmMain, I have a button that I want to use, to
access frmSliceInfo. How do I do that? I am able to access it from the
Main Menu, because it is under the FormContainer, but not from frmMain.
In frmMain, I tried Me.MDIParent.fr mSliceInfo but that did not work.

Thanx for your help.
--
Anil Gupte
www.keeninc.net
www.icinema.com


Sep 5 '07 #5
To add a module right click on the project name in the Solution Explorer,
then click Add Module. A module is lot like a class except it cannot be
instantiated. The object variables that you create do not take up much
memory. They merely act as pointers to your object.

In Module1 you should declare, but not instantiate your form object variables

Public F2 as Form2

I am still in the stone age working in Framework 1.0, so the following code
may be antiquated or even obsolete for 2.0 users...

but I tested this code and it works for me...

It would go in a form from where you want to open Form2, and where you have
a button called Button1.

'************

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click

If Not IsNothing(Modul e1.F2) AndAlso Module1.F2.Visi ble = False Then
'This applies after form has been closed
Module1.F2 = Nothing '(F2 does not test as nothing after being
closed.)
Module1.F2 = New Form2()
Module1.F2.Show ()
ElseIf IsNothing(Modul e1.F2) Then 'This applies first time form is
opened
Module1.F2 = New Form2()
Module1.F2.Show ()
Else 'This applies if form is visible and user clicks the button on
Form1 again
Module1.F2.Brin gToFront()
End If

End Sub

'************** ***

You don't have to put Form2 in a module. You could declare an object
variable as Form2 wherever you wanted to use it. The module in the code is
just acting as a handy repository.

You could name the instance of Form2 in Module1 as Form2 instead of F2, if
you like.

You could carry this over to a menu item (instead of the button) on your
MDI, and it would be accessible to any open form in the MDI form.

Sep 5 '07 #6
Also, the code I provided prevents users from opening multiple instances of
the form class. You could modify the code to allow multiple instances.
Sometimes it's a good idea to allow multiple instances, such as when a form
is used for a database search, and the user may want more than one result
available at the same time.

Sep 5 '07 #7
OK, cool I think this will work. Especially because I want to keep the form
active (i.e. it should not lose the information in it's textboxes) even
after I
switch to another form. Otherwise multiple instances would not have the
previous info in them

Thanx a lot! I will try it today.
--
Anil Gupte
www.keeninc.net
www.icinema.com

"Charlie" <c2****@yahoo.c omwrote in message
news:92******** *************** ***********@mic rosoft.com...
To add a module right click on the project name in the Solution Explorer,
then click Add Module. A module is lot like a class except it cannot be
instantiated. The object variables that you create do not take up much
memory. They merely act as pointers to your object.

In Module1 you should declare, but not instantiate your form object
variables

Public F2 as Form2

I am still in the stone age working in Framework 1.0, so the following
code
may be antiquated or even obsolete for 2.0 users...

but I tested this code and it works for me...

It would go in a form from where you want to open Form2, and where you
have
a button called Button1.

'************

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click

If Not IsNothing(Modul e1.F2) AndAlso Module1.F2.Visi ble = False
Then
'This applies after form has been closed
Module1.F2 = Nothing '(F2 does not test as nothing after being
closed.)
Module1.F2 = New Form2()
Module1.F2.Show ()
ElseIf IsNothing(Modul e1.F2) Then 'This applies first time form is
opened
Module1.F2 = New Form2()
Module1.F2.Show ()
Else 'This applies if form is visible and user clicks the button on
Form1 again
Module1.F2.Brin gToFront()
End If

End Sub

'************** ***

You don't have to put Form2 in a module. You could declare an object
variable as Form2 wherever you wanted to use it. The module in the code
is
just acting as a handy repository.

You could name the instance of Form2 in Module1 as Form2 instead of F2, if
you like.

You could carry this over to a menu item (instead of the button) on your
MDI, and it would be accessible to any open form in the MDI form.

Sep 6 '07 #8
It works, it's great. You are a cool cat! :-)

--
Anil Gupte
www.keeninc.net
www.icinema.com

"Charlie" <c2****@yahoo.c omwrote in message
news:1E******** *************** ***********@mic rosoft.com...
Also, the code I provided prevents users from opening multiple instances
of
the form class. You could modify the code to allow multiple instances.
Sometimes it's a good idea to allow multiple instances, such as when a
form
is used for a database search, and the user may want more than one result
available at the same time.

Sep 7 '07 #9
OK, unfortunately I have a problem.

As I said this works, but now the form2 is not recognized as an mdichild of
the container form. I tried to instantiate it in the conainer load event.
But that gives me some wierd behavior. What happens is that when I call
form 2 from form1, as soon as I complete some task in form 2 it returns to
form1 without asking. Here is the code in FormContainer:
Private Sub FormContainer_L oad(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
' ***********This is your code
If Not IsNothing(L3Glo balModule.frmSl iceInfo) AndAlso
L3GlobalModule. frmSliceInfo.Vi sible = False Then 'This applies after form
has been closed
L3GlobalModule. frmSliceInfo = Nothing '(frmSliceInfo does not test
as nothing after being closed)
L3GlobalModule. frmSliceInfo = New FormSliceInfo
L3GlobalModule. frmSliceInfo.Sh ow()
ElseIf IsNothing(L3Glo balModule.frmSl iceInfo) Then 'This applies first
time form is opened
L3GlobalModule. frmSliceInfo = New FormSliceInfo
L3GlobalModule. frmSliceInfo.Sh ow()
Else 'This applies if form is visible and user clicks the button on
Form1 again
L3GlobalModule. frmSliceInfo.Br ingToFront()
L3GlobalModule. frmSliceInfo.Wi ndowState = FormWindowState .Maximized
End If
' ***********This is your code
L3GlobalModule. frmSliceInfo.Md iParent = Me
L3GlobalModule. frmSliceInfo.Lo cation = Me.Location
L3GlobalModule. frmSliceInfo.Si ze = Me.Size
L3GlobalModule. frmSliceInfo.Do ck = DockStyle.Fill

frmMain.MdiPare nt = Me
frmMain.Locatio n = Me.Location
frmMain.Size = Me.Size
frmMain.Dock = DockStyle.Fill
'************** **********
......
Now in FormMain, I have a button called AdvancedPrice:

Private Sub btnAdvancedPric e_Click(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles btnAdvancedPric e.Click
' ***********This is your code
If Not IsNothing(L3Glo balModule.frmSl iceInfo) AndAlso
L3GlobalModule. frmSliceInfo.Vi sible = False Then 'This applies after form
has been closed
L3GlobalModule. frmSliceInfo = Nothing '(frmSliceInfo does not test
as nothing after being closed)
L3GlobalModule. frmSliceInfo = New FormSliceInfo
L3GlobalModule. frmSliceInfo.Sh ow()
ElseIf IsNothing(L3Glo balModule.frmSl iceInfo) Then 'This applies first
time form is opened
L3GlobalModule. frmSliceInfo = New FormSliceInfo
L3GlobalModule. frmSliceInfo.Sh ow()
Else 'This applies if form is visible and user clicks the button on
Form1 again
L3GlobalModule. frmSliceInfo.Br ingToFront()
L3GlobalModule. frmSliceInfo.Wi ndowState = FormWindowState .Maximized
' ***********This is your code

In FormSliceInfo, I am having the user pick a text file, I then read it and
fill a multiline text box with it. As soon as I read the file it goes back
to FormMain. I stepped through it and saw that it was doing so as soon as
the textbox was filled.

What is going on? Please help, I am flummoxed!
Thanx,
--
Anil Gupte
www.keeninc.net
www.icinema.com

"Charlie" <c2****@yahoo.c omwrote in message
news:92******** *************** ***********@mic rosoft.com...
To add a module right click on the project name in the Solution Explorer,
then click Add Module. A module is lot like a class except it cannot be
instantiated. The object variables that you create do not take up much
memory. They merely act as pointers to your object.

In Module1 you should declare, but not instantiate your form object
variables

Public F2 as Form2

I am still in the stone age working in Framework 1.0, so the following
code
may be antiquated or even obsolete for 2.0 users...

but I tested this code and it works for me...

It would go in a form from where you want to open Form2, and where you
have
a button called Button1.

'************

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click

If Not IsNothing(Modul e1.F2) AndAlso Module1.F2.Visi ble = False
Then
'This applies after form has been closed
Module1.F2 = Nothing '(F2 does not test as nothing after being
closed.)
Module1.F2 = New Form2()
Module1.F2.Show ()
ElseIf IsNothing(Modul e1.F2) Then 'This applies first time form is
opened
Module1.F2 = New Form2()
Module1.F2.Show ()
Else 'This applies if form is visible and user clicks the button on
Form1 again
Module1.F2.Brin gToFront()
End If

End Sub

'************** ***

You don't have to put Form2 in a module. You could declare an object
variable as Form2 wherever you wanted to use it. The module in the code
is
just acting as a handy repository.

You could name the instance of Form2 in Module1 as Form2 instead of F2, if
you like.

You could carry this over to a menu item (instead of the button) on your
MDI, and it would be accessible to any open form in the MDI form.

Sep 7 '07 #10

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

Similar topics

3
11294
by: Peter Rohleder | last post by:
Hi, I'm using a style-sheet where I make use of the XPATH-"following-sibling"-expression. The part which makes problems looks similar to the following code: --------------------------- <xsl:for-each select="headdata/extension/person">
2
1940
by: Ferd Biffle | last post by:
Hello! I have an Excel XML feed from an Enterprise PDM system that is basically a flat text file with XML tags: <?xml version="1.0" encoding="UTF-8"?> <Import> <Row> <ID>1</ID> <Level>0</Level>
8
7640
by: Frances Del Rio | last post by:
I'm getting Getting "Access is Denied" on resizeTo and moveTo methods in IE (IE 6.0..) I saw two posts about this from 7/6 & 7/7.. I suspect, like previous poster said, that this has to do w/MS Windows Updates (Tools --> Windows Update in IE..) because this started happening to me recently (ONLY in IE, works fine in N7), and I updated about...
25
10192
by: Lyn | last post by:
Hi, I am working on a genealogy form. The only table (so far) lists everybody in the family, one record per person. Each record has an autonum ID. The parent form (frmMainForm) displays the data in each record, which includes the ID of the father and the mother (who also have records in the table). One record per form. I have a Tab...
11
2132
by: localpricemaps | last post by:
i have some html which looks like this where i want to scrape out the href stuff (the www.cnn.com part) <div class="noFood">Cheese</div> <div class="food">Blue</div> <a class="btn" href = "http://www.cnn.com"> so i wrote this code which scrapes it perfectly:
1
1787
by: Sion Arrowsmith | last post by:
I have a module which needs to know what directory it's in, and to refer to files in a sibling directory, something like App/src/foo.py wants to read App/data/conf.xml . But I have no idea in what context foo.py is going to be run -- it could be being run as a script, it could be being imported as a module by another script from anywhere in...
6
96009
NeoPa
by: NeoPa | last post by:
Introduction The first thing to understand about Sub-Forms is that, to add a form onto another form takes a special Subform control. This Subform control acts as a container for the form that you want to act as a Sub-Form of the main one. That is to say, if you wanted frmB to act as a Sub-Form of frmA, then you would create a Subform control...
4
2765
by: Debbiedo | last post by:
My software program outputs an XML Driving Directions file that I need to input into an Access table (although if need be I can import a dbf or xls) so that I can relate one of the fields (fromStop) and its associated driving directions back to a relational database. I have asked my software vendor for solutions but thus far they have not come...
3
3976
by: apurvaG | last post by:
Hi All, I am facing a problem while fetching a preceding sibling with some specific name from current node. Following is the sample XML which I am using <Root> <document> <tid>100</tid> <location>SB</location>
0
7857
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8137
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8299
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7890
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6545
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5667
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3813
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2297
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 we have to send another system
0
1127
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.