How do I control the number of same MDI Child Form?

G

Guest

Hello, I have not been able to find any reference on the great www on how to
control the number of same MDI Child Forms. Basically i want to prevent my
users from opening more than one copy of the same child form in certain
circumstances.

this kinda works but i would have to reset the static var when i close the
form... is there a better way?

Private Sub mnuItem_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles mnuItem.Click
Dim MyChildForm As New frmNameHere
Static intCount As Integer 'STATIC TO MAINTAINS ITS VALUE

'INCREMENT THE CAPTION COUNTER.
intCount += 1

If intCount <= 1 Then
Me.Text = Me.Text & " - " & MyChildForm .Text '& " " &
intCount.ToString()
With MyChildForm
.MdiParent = Me
.Show()
End With
End If
End Sub


Please help

THX
 
G

Guest

NM I got it.... here's the solution I found in some of my old code from class.

Private Sub mnuShift_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles mnuShift.Click
Dim blnFormExists As Boolean = False

blnFormExists = CheckFormExistence("frmShift")

If Not blnFormExists Then
Dim frmaboutInstance As New frmShift
With frmaboutInstance
.MdiParent = Me
.Show()
End With
End If
End Sub

Private Function CheckFormExistence(ByVal strFormName As String) As Boolean
'Determine if form already exists
Dim frmTest As Form
Dim blnFound As Boolean = False

'Does form already exist?
For Each frmTest In Me.MdiChildren
With frmTest
If .Name = strFormName Then
.Activate() 'Activate previous instance
blnFound = True
End If
End With
Next
Return blnFound
End Function
 
Joined
Jun 23, 2005
Messages
1
Reaction score
0
Using Dispose method

Hi,

Its quite easy one yaar.

If its docable window then

///////////////////////////////////////
private void button1_Click(object sender, System.EventArgs e)
{
Form2 form=new Form2();
form.ShowDialog();
}
////////** Its wont allow to move the control to the main window **////////////////
///////////////////////////////////////

If its Non-docable window then,

///////////////////////////////////////
Declare a varible gloabaly consider val=0;

private void button1_Click(object sender, System.EventArgs e)
{
Form2 form2=new Form2();
if(val==0)
{
if(!form2.IsDisposed)
{
form2.WindowState=FormWindowState.Normal;
form2.ShowDialog(); val=1;
}
}
}

///////////////////////////////////////
Thanks and regards

Venkatesan Prabu.J
HCL Technologies
Chennai
 
G

Guest

Thx J but, I like my way a bit better since it does activate and bring
forward if already open. thx anyway.
 

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