Mdi Concept questions

S

Stan Sainte-Rose

Hi,
Sorry about this newbie question, but I have some questions about the MDI
Concept.

I have a MdiParent form that calls a Child Form (A).
This Child Form (A) could call another Form (B).

Example.
My main Form is the MDI Parent Form.
I have a button that launches a Customer Listing (Child Form A).
When I want to get the details of one customer I load the (Child Form B)

How to set each Child for having the same MdiParent ?

Stan
 
H

Herfried K. Wagner [MVP]

* "Stan Sainte-Rose said:
Sorry about this newbie question, but I have some questions about the MDI
Concept.

I have a MdiParent form that calls a Child Form (A).
This Child Form (A) could call another Form (B).

Example.
My main Form is the MDI Parent Form.
I have a button that launches a Customer Listing (Child Form A).
When I want to get the details of one customer I load the (Child Form B)

How to set each Child for having the same MdiParent ?

\\\
Dim f As New FormB()
f.MdiParent = Me.MdiParent
f.Show()
///
 
S

Stan Sainte-Rose

Thanks Herfried,

I forgot to say
I call the Child Form A like this.

Dim f As New FormA()
f.MdiParent = Me
---> Panel1.Controls.Add(f)
f.Show()

I use a Panel Control
But I don't know how to call the Form B using the same syntax.

Stan
 
H

Herfried K. Wagner [MVP]

* "Stan Sainte-Rose said:
I forgot to say
I call the Child Form A like this.

Dim f As New FormA()
f.MdiParent = Me
---> Panel1.Controls.Add(f)
f.Show()

This won't work. You will have to set the form's 'TopLevel' property to
'False'. But I don't understand why you don't use an MDI environment.
You can try something like this:

\\\
f.Parent = Me.Parent
///
 
S

Stan Sainte-Rose

Herfried,

I ve tried what you said. but it doesn't work.

The MDIContainer is A
And I have 2 Child Forms B and C.
C is called by B

I don't have problem with the B
And I use the bit of code that I ve sent.

When I minimize B it appears at the bottom of the Panel1 (not in the
taskbar)

I would like to do the same thing with the C knowing B is not a MdiContainer
but it's B that loads C.
Using the the first code you ve sent it works, but when I minimize C, it
appears in the taskbar.
not in the Panel1.

Any idea ?
Stan
 
C

Cor Ligthert

Hi Stan,

Is it something like this you are looking for?

Cor

\\\The container
Public Shared A As New Form2
Public Shared B As New Form3
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
A.MdiParent = Me
B.MdiParent = Me
A.Show()
End Sub
////
\\\The Midi's
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Form1.B.Show()
Me.Hide()
End Sub
////
 
H

Herfried K. Wagner [MVP]

* "Stan Sainte-Rose said:
I ve tried what you said. but it doesn't work.

The MDIContainer is A
And I have 2 Child Forms B and C.
C is called by B

I don't have problem with the B
And I use the bit of code that I ve sent.

When I minimize B it appears at the bottom of the Panel1 (not in the
taskbar)

I would like to do the same thing with the C knowing B is not a MdiContainer
but it's B that loads C.
Using the the first code you ve sent it works, but when I minimize C, it
appears in the taskbar.

No! When setting your instance of form C's 'MdiParent' property to your
instance of form B, which is an MDI child, then it should not be shown
in the taskbar too. Code for form B:

\\\
Dim c As New FormC()
c.MdiParent = Me
c.Show()
///
 
S

Stan Sainte-Rose

Cor and Herfried,

I talk to fast :(

It works but..

Here's my code..
Container :
Public Shared B As Form1
Public Shared C As New Form2

Private Sub OutlookBar1_ButtonClick(ByVal sender As Object, ByVal e As
OutlookBar.OutlookBarButtonClickEventArgs) Handles OutlookBar1.ButtonClick
C.TopLevel = False
C.MdiParent = Me
Panel1.Controls.Add(C)
If Not IsNothing(B) Then
If Not B.IsDisposed Then
B.WindowState = FormWindowState.Normal
B.BringToFront()
Else
B = New Form1
B.MdiParent = Me
Panel1.Controls.Add(B)
B.Show()
End If
Else
B = New Form1
B.MdiParent = Me
Panel1.Controls.Add(B)
B.Show()
End If
End Sub


From the B (Child)
A.C.IDCUSTOMER = IDCUSTOMER
A.C.Show()

So my problem is :
The C child is displayed when I doubleclick on a customer from B. (so I said
it works).
The C appears in the Panel1 and when I minimize it it works fine.

But, if I doubleclick, trying to display another customer from B, it doesn't
work.

If I close the C child, I could not get another C child if I doubleclick on
B.

Maybe I miss something.

Stan
 
S

Stan Sainte-Rose

It's okay....

here's what I do..

From B
Dim C As New FormC
C.TopLevel = False
C.IDCUSTOMER = idcustomer
C.Parent = Me.Parent ' (Parent is the MDIContainer)
C.Show()

It seems it works fine..

Stan
 
S

Stan Sainte-Rose

My last question about this topic is how to prevent if a Child Form C is not
yet loaded.
I mean, if a Customer Form is loaded, and I click again on the Form B on the
same Customer
I would like to bring to front the loaded form instead of to have 2 times
the same Form C.
Like I did for the Form B where I just can have one instance.

Stan
 
C

Cor Ligthert

Hi Stan,

In my approach what you did not follow completly ( not that it is a problem)
you are using all the time the same form with the same information.

In the approach from Herfried you are using every time a new form with new
information.

I think that mixing those two will bring you to your solution.

Cor
 
S

Stan Sainte-Rose

Cor,
Yes, I think I resolve my problem using the 2 approaches and I thank you and
I see how works mdi (until I get a new problem :) )
By the way, How to know if a Child is already loaded ?
By child I mean a Distinct Customer Form, I can have several Opened Customer
Forms but I don't want to have
more than 1 same Customer Form.

Is there a way before opening the Customer Form, to check all opened child
form and test their Name.
I store the IDCustomer into the Name Property. ?

Stan
 
C

Cor Ligthert

Hi Stan,

I never do it this way, however you can try this

\\\
Dim A As New Form2
A.MdiParent = Me
A.Show()
If A.Created = True Then
MessageBox.Show("I am open")
End If
A.Close()
if A.Created = False Then
MessageBox.Show("I am not open")
End If
///

I hope this helps a little bit?

Cor
 
S

Stan Sainte-Rose

Cor,

Reading your code, I think it won't help me.
In fact, when I open a Form2 (I give it a name that is my IDCustomer).
But I think I have to read all the opened form to check.

Something like this but my code doesn't work

Private Sub ChargeCLient(ByVal idclient As Integer)
Me.WindowState = FormWindowState.Minimized
Dim f As Form
For Each f In Me.MdiChildren
If f.Name = idcustomer.ToString Then
Exit Sub
End If
Next
Dim C As New Form2
C.Name = idcustomer.ToString
C.TopLevel = False
C.IDCUSTOMER = idcustomer
C.Parent = Me.Parent
C.Show()
End Sub


Any idea ?

Stan
 
S

Stan Sainte-Rose

Ooops Cor, I m sorry, don't feel like that..
My english is so poor than I think you don't take it cool..
Anyway I ve tested what you ve written and it doesn't work like I want.
But I think it's inside the idea.

Stan
 
C

Cor Ligthert

Stan,

Can you show how you did tried my sample?
From your part of the code it is to much guessing for me now.

Cor

Ooops Cor, I m sorry, don't feel like that..
 
S

Stan Sainte-Rose

Hi Cor,

I didn't say it doesn't work...it works...
But what I want is to prevent that the same Form is opened.
A form for me is a Unique Customer Form (A.Name=Idcustomer)
I know I m not clear.
Guess I have a list with 5 IDcustomer
1,2,3,4,5

I can have at the same time a form for each IDCustomer,
but not I don't not have twice a form with the same IDcustomer
Maybe what I have to do, is to send the IDcustomer as name
(something like Dim eval(idcustomer) as New Form3), but I suppose it doesn't
work)

By reading Herfried's reply on my latest post, he said my code is not a real
MDI Form.
So I think I m in trouble... hum hum..
I suppose I have to open the different ChildForm from my real MDIContainer
that is my Main Menu
So that means, when I doubleclick on a customer ID from my CustomerList Form
(it's a child form)
I have to find a way to send back the event to the MDIContainer.

Thanks once again for your support..
Stan

Here's the code that you asked for.
Dim A As New Form3
A.TopLevel = False
A.Parent = Me.Parent
A.IDCUSTOMER = idcustomer
A.Name = idcustomer.ToString
A.Show()
If A.Created = True Then
MessageBox.Show("I am open")
End If
A.Close()
If A.Created = False Then
MessageBox.Show("I am not open")
End If
 
C

Cor Ligthert

Hi Stan,

I think something like this is what you mean, here for only customer one of
course.

You can try it, I am curious it it goes?
(I tested it with only the one)

Cor

\\\
Dim frmExist As Boolean
For Each frm As Form In Me.ParentForm.MdiChildren
If frm.Name = "Form3" Then
If DirectCast(frm, Form3).Id = 1 Then
frm.BringToFront()
frmExist = True
End If
End If
Next
If Not frmExist Then
Dim frmNew As New Form3
frmNew.MdiParent = Me.ParentForm
frmNew.Show()
frmNew.Name = "Form3"
frmNew.BringToFront()
frmNew.Id = 1
End If
///
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top