MDI

T

The Clansman

Hi,
I have a MDI parenf form, I have this code to load a child form:

Dim f As New frmAddUser

f.MdiParent = Me
f.Show()

this is a button procedure, the problem is that every time I click the
button, the mdiform is added to the mdiparent, how do I prevent it?? I want
to add the child form only if that form is not loaded.

thanks
 
C

Cor Ligthert

Hi Clansman,

I use this for what you ask.

I hope this works for you as well?

Cor

\\\
Private Sub mnuTabelResults_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles mnuTabelResults.Click
mnuFrmHandling("Results")
End Sub
Private Sub mnuFrmHandling(ByVal frmName As String)
Dim frmExist As Boolean
For Each frm As Form In Me.MdiChildren
If frm.Name = frmName Then
frmExist = True
frm.BringToFront()
End If
Next
If Not frmExist Then
Dim frmNew As Form
Select Case frmName
Case "Persons"
frmNew = New frmPersons
Case Else
frmNew = New frmTabels(frmName)
End Select
frmNew.MdiParent = Me
frmNew.Show()
frmNew.WindowState = FormWindowState.Maximized
frmNew.Name = frmName
frmNew.BringToFront()
End If
End Sub
////
 
J

Jeff Johnson

\\\
Private Sub mnuTabelResults_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles mnuTabelResults.Click
mnuFrmHandling("Results")
End Sub
Private Sub mnuFrmHandling(ByVal frmName As String)
Dim frmExist As Boolean
For Each frm As Form In Me.MdiChildren
If frm.Name = frmName Then
frmExist = True
frm.BringToFront()

Personally I'd drop the frmExist variable (and the test of it further down)
and just put an Exit Sub right here. At the very least an Exit For, because
there's no point in continuing the loop once you've found the form. Granted,
you're not going to have thousands of MDI children, but it's the principle
of the thing....
 
C

Cor Ligthert

Hi Jeff,

You are right, I will change it, makes it nicer.
(Probably it comes that I do not like Exit commands, they are a little bit
look a like Goto's for me, however with those inline ones I have less
problems)

:)

Thanks

Cor
 
J

Jeff Johnson

You are right, I will change it, makes it nicer.
(Probably it comes that I do not like Exit commands, they are a little bit
look a like Goto's for me, however with those inline ones I have less
problems)

Would you feel better going the .NET route and using Return instead?

Personally I've never had a problem with Exit xxx. It's basically VB's
equivalent of C's break and return statements. And if it's good enough for
C....
 
C

Cor Ligthert

Hi Jeff,

Can you explain to me what is the .Net route and the return? I think that I
cannot answer you when I am not sure what you mean with that?

In my opinion is the return only a programmaticly added feature that started
with the introduction of the C type languages.

Cor
 
J

Jeff Johnson [MVP: VB]

Can you explain to me what is the .Net route and the return? I think that I
cannot answer you when I am not sure what you mean with that?

I meant instead of my suggestion of using Exit Sub you could use Return
instead. Then you could bypass your dislike of Exit commands.
In my opinion is the return only a programmaticly added feature that started
with the introduction of the C type languages.

The concept of Return is as old as programming. Most machine language
instruction sets have an opcode to do this. BASIC used to use Return in
conjunction with GoSub back in the days before it had real procedures. In my
opinion, Return is long overdue in its current usage. Better late than
never, I guess.
 
C

Cor Ligthert

Hi Jeff,

The oldest return I know is the 15,15 (I thought it was) it is the branch
unconditional to the address set in the standard register.

However, that is not what I meant here.

The fact that always is set a return value when a function exit is in my
idea younger and I assume from the start of the C time, however that is for
something for what I will not set a cent...

In addition, because I know the wrong things from that Return I show above,
you will not see me use that when it is not in the context of the code.
(What it is in my opinion not here). I use a return when it really returns a
value.

To be clearer I am a Dijkstra adept.

:)

Cor
 

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