Cannot open the form

V

Vivek

Hi,

I am using this code to open the form...
---------------------------------------------------------------------------------------
Private frmAddUser as AddUser()
Dim fc As Form
For Each fc In Me.MdiParent.MdiChildren

If fc Is frmAddUser Then

If fc.WindowState = FormWindowState.Minimized Then

fc.WindowState = FormWindowState.Normal

End If

fc.Show()

fc.Focus()

Return

End If

Next

If (frmAddUser Is Nothing) Then

frmAddUser = New AddUser

frmAddUser.MdiParent = Me.MdiParent

frmAddUser.Show()

End If

---------------------------------------------------------------------

When I close the form and try to reopen it does not open the form. It still recognises that frmAddUser exists. How do I kill the instance when I close the form?

Thanks

Vivek
 
K

Ken Tucker [MVP]

Hi,

If the form is already a mdichild try fc.bringtofront instead of
fc.show to reshow the form

http://msdn.microsoft.com/library/d...windowsformscontrolclassbringtofronttopic.asp


Ken
--------------------
Hi,

I am using this code to open the form...
---------------------------------------------------------------------------------------
Private frmAddUser as AddUser()
Dim fc As Form
For Each fc In Me.MdiParent.MdiChildren
If fc Is frmAddUser Then
If fc.WindowState = FormWindowState.Minimized Then
fc.WindowState = FormWindowState.Normal
End If
fc.Show()
fc.Focus()
Return
End If
Next
If (frmAddUser Is Nothing) Then
frmAddUser = New AddUser
frmAddUser.MdiParent = Me.MdiParent
frmAddUser.Show()
End If
---------------------------------------------------------------------
When I close the form and try to reopen it does not open the form. It still
recognises that frmAddUser exists. How do I kill the instance when I close
the form?
Thanks
Vivek
 
A

Armin Zingler

Vivek said:
I am using this code to open the form...
-------------------------------------------------------------
-------------------------- Private frmAddUser as AddUser()
Dim fc As Form
For Each fc In Me.MdiParent.MdiChildren

If fc Is frmAddUser Then

If fc.WindowState = FormWindowState.Minimized Then

fc.WindowState = FormWindowState.Normal

End If

fc.Show()

fc.Focus()

Return

End If

Next

If (frmAddUser Is Nothing) Then

frmAddUser = New AddUser

frmAddUser.MdiParent = Me.MdiParent

frmAddUser.Show()

End If

---------------------------------------------------------------
------

When I close the form and try to reopen it does not open the form. It
still recognises that frmAddUser exists. How do I kill the instance
when I close the form?


You can remove the reference (frmAdduser=nothing) by handling the Closed
event of the form (declare frmadduser withevents or use addhandler to attach
the event handler). BTW, within the first If..Endif block, try
frmAdduser.Activate instead (and maybe .Show additionally because
..Activate is sometimes not enough).


Ar min
 
P

Peter Proost

Hi, maybe this can help you, I hope the code is clear otherwise feel free to
ask:

Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles _ MenuItem2.Click
If checkFormOpen = False Then
Dim obj As New Form2
obj.MdiParent = Me
obj.WindowState = FormWindowState.Maximized
obj.Show()
End If
End Sub

Private Function checkFormOpen() As Boolean
Dim objForm As Form
For Each objForm In Me.MdiChildren
If TypeOf objForm Is Form2 Then
objForm.WindowState = FormWindowState.Maximized
objForm.BringToFront()
Return True
End If
Next
Return False
End Function
 
C

Cor Ligthert

Vivek,

Will you please sent next time not in HTML format, and as well in a better
readable way, with all those linespaces it is almost impossible to get a
good idea what you are doing.

Probably is the only thing you want to do something as
\\\
If frmAddUser.isdisposed then
frmAddUser is new AddUser
End if
frmAddUser.show
///
I hope this helps,

Cor
 
V

Vivek

Thanks.

I tried this but got an error
Private Sub AddUserToolStripMenuItem_Click_1(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
AddUserToolStripMenuItem.Click
Dim fc As Form

For Each fc In Me.MdiParent.MdiChildren
If fc Is frmAddUser Then

If fc.WindowState = FormWindowState.Minimized Then
fc.WindowState = FormWindowState.Normal
End If
fc.Show()
fc.Focus()
Return
End If
Next

If (frmAddUser.IsDisposed) Then
frmAddUser = New AddUser
frmAddUser.MdiParent = Me.MdiParent
End If

frmAddUser.Show()

End Sub
 
C

Cor Ligthert

Vivek,

Tell next time what the error is, that makes it much easier to give an
answer, now it still is a gues. See in line what is probably the solution to
the error.

(This is another approach and basicly the one I take, my sample I showed you
was in the way Herfried does it, which is shorter however remove that again)
I tried this but got an error
Private Sub AddUserToolStripMenuItem_Click_1(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
AddUserToolStripMenuItem.Click
Dim fc As Form

For Each fc In Me.MdiParent.MdiChildren

If fc.Name = "AddUser" Then

Or 'that I never did

If typeof fc Is AddUser Then
If fc.WindowState = FormWindowState.Minimized Then
fc.WindowState = FormWindowState.Normal
End If
fc.Show()
Return
End If
Next
frmAddUser.Show()

I hope this helps,

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