Cannot hide form

rapture

Member
Joined
May 19, 2005
Messages
10
Programming Experience
Beginner
I am trying to hide a form but cannot seem to get it to work. Here is snippet of the code:

VB.NET:
 [size=2][color=#0000ff]
Private[/color][/size][size=2][color=#0000ff]Sub[/color][/size][size=2] myForm_Load([/size][size=2][color=#0000ff]ByVal[/color][/size][size=2] eventSender [/size][size=2][color=#0000ff]As[/color][/size][size=2] System.Object, [/size][size=2][color=#0000ff]ByVal[/color][/size][size=2] eventArgs [/size][size=2][color=#0000ff]As[/color][/size][size=2] System.EventArgs) [/size][size=2][color=#0000ff]Handles[/color][/size][size=2][color=#0000ff]MyBase[/color][/size][size=2].Load
 
[/size][size=2]
[/size][size=2][color=#008000]'Display the form[/color][/size]
[color=black]myForm[/color][size=2].DefInstance.Show()[/size]
 
[size=2][color=green]'Some code goes here which calls another app[/color][/size]
[size=2]
[/size]
[size=2][color=#008000]'Hide the form[/color][/size]
[size=2]myForm.DefInstance.Hide()
[/size][size=2][color=#0000ff]End[/color][/size][size=2][color=#0000ff]Sub
 
[/color][/size]

The from appears to disappear momentarily but then reappears. I need this form loaded in the background but invisible to the user once the app it calls is loaded. I am not working with multiple forms which is why I stuck with the default form instead of instantiating. Any ideas how to get this to work?

Thanks
 
I need to load an application which requires that I switch some registry settings prior to starting the application. Then while the application is running, I need to listen for particular commands issued from the application and when certain commands are issued to launch a couple of custom forms.
When the application is closed then I need to restore the previous registry settings.
This is why I need the form/app running in the background to listen to and respond to these events.

Thanks for your help
 
Firstly, I would get rid of that DefInstance stuff. DefInstance really only exists to allow certain VB6 code to be upgraded gracefully. You shouldn't really be writing new code that uses DefInstance.

Secondly, why are you calling Show on a form in its own Load event handler. It's already being shown if it the Load event has been raised. Once the Load event handler completes the form will be visible even if you call Hide.

If you want an app running but not visible, set the form's WindowState to Minimized and the ShowInTaskbar property to False.
 
Yes you are absolutely right. I am completely new to VB and have just upgraded this project from VB6. This is why the DefInstance stuff is included. I think I am spending too much time trying to get the app running exactly as it did in the past even though I upgraded to VB.NET. This is compounded by the fact that I am learning VB.NET and trying to understand the old Vb6 code and trying to find its equivalent function in VB.NET.
I am going to start writing this app from scratch using proper VB.NET code. I will post again when I have further questions as I am sure I will.

Thanks
 
Back
Top