473,387 Members | 1,687 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Redisplaying modeless window.


Suppose you have Button1 on Form1. If the user clicks Button1, I want
to show Form2 modelessly. If Form2 is already open I just want to
redisplay it, not open a new window. Thru trial and error I came up
with the following code. Is there a better way to do this?
Public Class Form1
Dim objForm As Form2

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

If (IsNothing(objForm)) Then
objForm = New Form2
objForm.Show()
Else
If (objForm.Created) Then
objForm.BringToFront()
Else
objForm = New Form2
objForm.Show()
End If
End If

End Sub

End Class
Dec 4 '07 #1
2 1447
I guess it depends on what kind of 'state' the Form2 can be in. What you
have here won't work if the form was hidden or minimized. Have a minimize
button on Form2? Have any other button that causes a Me.Hide?
--
Terry
"cr***@hotmail.com" wrote:
>
Suppose you have Button1 on Form1. If the user clicks Button1, I want
to show Form2 modelessly. If Form2 is already open I just want to
redisplay it, not open a new window. Thru trial and error I came up
with the following code. Is there a better way to do this?
Public Class Form1
Dim objForm As Form2

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

If (IsNothing(objForm)) Then
objForm = New Form2
objForm.Show()
Else
If (objForm.Created) Then
objForm.BringToFront()
Else
objForm = New Form2
objForm.Show()
End If
End If

End Sub

End Class
Dec 5 '07 #2
On Dec 4, 7:01 pm, Terry <Ter...@nospam.nospamwrote:
I guess it depends on what kind of 'state' the Form2 can be in. What you
have here won't work if the form was hidden or minimized. Have a minimize
button on Form2? Have any other button that causes a Me.Hide?
Good point. I replaced the BringToFront method with a Dispose and New
Form and it seems to work. Thanks!

Public Class Form1
Dim objForm As Form2

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

If (IsNothing(objForm)) Then
objForm = New Form2
objForm.Show()
Else
If (objForm.Created) Then
objForm.Dispose 'changed from BringToFront
objForm = New Form2
objForm.Show()
Else
objForm = New Form2
objForm.Show()
End If
End If

End Sub

End Class
Dec 5 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Rikkert | last post by:
I can't get my custom-made modeless dialog box (Visual C++.net Win32) to respond to clicking the close button or pressing Alt-F4. I am using the IsDialogMessage to check if messages are for my...
8
by: vince | last post by:
I have a windows app whose main dialog contains a button that launches a form. I've tried using Form.Show() to have it launch as a modeless form, but it behaves as if it's modal (i.e. parent form...
6
by: Gary Miller | last post by:
Does anyone know how to detect a modeless form on closing by the form that invoked the modeless form? form.Show();
4
by: Steve | last post by:
I have the MDI MFC application ported to .NET. Now this application include mixed managed/unmanaged code. The application displays progress dialog with the cancel button during lenghtly...
2
by: proit_123 | last post by:
I am working on a windows forms application and have the following requirement. · I need to display a modeless dialog from the main form. o This allows user to continue to work with the...
0
by: Ralstoj | last post by:
Hi I am programing in Autocad with VB Autodesk have not given users access to new note function in Autocad CIVIL3d API. I am trying to work round this by creating notes using the sendkey...
1
by: sowen | last post by:
In IE, I am using showModalDialog to pop up a modeless window, then the object "opener" is undefined. well, I pass the parent window object as an argument to pop up, then I can redirect the...
3
by: AdamMorris | last post by:
I have a very interesting problem and can't seem to figure it out. Basically I'm trying to make a Training Assistant: a window that will guide the user through the setup process of an online app....
3
by: DoB | last post by:
What is the preferred way to refresh modeless dialogs? I am using the modeless dialog that shows a progress of a sequential process. The dialog class has nonvisual properties containg the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.