Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

form as a popup 1

Status
Not open for further replies.

zianole

Programmer
Jan 9, 2007
16
Can i close a dialog (child) form by clicking outside the boundries of form. Actuall I want a form to behave like a popup, but show as a dialog form. Is it possible?
thanks
 
Try this: (not tested)

Show the form (not showdialog) and have the topmost set to true. Close the form (me.close) in the lostfocus event.
 
Thanks TipGiver.

your solution is very easy. I tried your idea in following code. Because I need behaviour of showdialog (pause processing untill form close), So using while loop until form close. Please suggest, is there simpler way?

<<<<<<<<<< CODE >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

Public Class Form1
Inherits System.Windows.Forms.Form
Dim formClosed As Boolean

Public Sub ShowLikeDialog()
formClosed = False
Me.TopMost = True
Me.Show()
While formClosed = False
Application.DoEvents()
End While
End Sub

Private Sub Form1_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.LostFocus
formClosed = True
Me.Close()
End Sub

End Class

<<<<<<<<<< END CODE >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
 
Above code is working fine on blank form but I found that lostfocus call automatically whenever focus goes to any control on same form.
For example when I put a textbox control on form, form lostfocus event called automatically after form.show call, so form disapears right after show.
I am using .net2003
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top