|
-
Jan 1st, 2012, 01:30 PM
#1
Me.Hide
Hi,
I don't understand why this doesn't work: -
Code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Hide()
Initiate()
End Sub
The Initiate subroutine is ok, but the form is displayed, since I'm trying to write a program to work in the background I'm a bit displeased.
I tried Me.Visible = False, but: -
(a) I'm surprised it wasn't flagged as an error... I don't believe Forms have a Visible attribute.
(b) That didn't work either.
I'm pretty sure I've used Me.Hide in this way before, (I'm on vacation with a new laptop so I don't have previous projects to check) This machine's OS is Win.7 64Bit I'm wondering if that has any bearing.
Hopefully I'm doing something basically wrong and you guys can put me straight or if I'm not, you can suggest something else.
Poppa.
Along with the sunshine there has to be a little rain sometime.
-
Jan 1st, 2012, 02:20 PM
#2
Re: Me.Hide
What is it that you're trying to do exactly? A Windows Form project is just that. A project for Windows Forms. If you don't want a form, then don't create a Windows Form project.
Instead, you could create a Windows service. That will allow you to do the background work without a form.
Alternatively, though a lazier method, would be to set the transparency property of the form to a specific color. Change the background color to that color and make the form borderless.
But then you'd still have to hide the form from the taskbar and a true background program would need to use a Windows API to hide the program from Alt+Tab.
CodeBank contributions: Process Manager, Temp File Cleaner
 Originally Posted by SJWhiteley
"game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....
-
Jan 1st, 2012, 03:21 PM
#3
Re: Me.Hide
Thanks Weirddemon, I knew it had to be something basic.
I was trying out some of the algorithms I was inventing and used a form to display the results... Then the idea was to just hide the form.
I'll see how I get on with a Service... That'll be something new.
Poppa.
Along with the sunshine there has to be a little rain sometime.
-
Jan 1st, 2012, 03:53 PM
#4
Re: Me.Hide
 Originally Posted by Poppa Mintin
Thanks Weirddemon, I knew it had to be something basic.
I was trying out some of the algorithms I was inventing and used a form to display the results... Then the idea was to just hide the form.
I'll see how I get on with a Service... That'll be something new.
Poppa.
As long as you're not interacting with the desktop, services are simple and great for background work.
CodeBank contributions: Process Manager, Temp File Cleaner
 Originally Posted by SJWhiteley
"game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....
-
Jan 1st, 2012, 04:57 PM
#5
Re: Me.Hide
And, as for the problem at hand - you're executing this code in the form's Load event, that is before the form is actually shown. You can hide it immediately in the Shown event instead:
Code:
Private Sub Form1_Shown(ByVal e As EventArgs, ByVal sender As Object) Handles Me.Shown
Me.Hide()
End Sub
Last edited by minitech; Jan 2nd, 2012 at 11:19 AM.
-
Jan 1st, 2012, 08:06 PM
#6
Re: Me.Hide
 Originally Posted by minitech
or (even better) set Visible to False in your form's designer or constructor...
Thanks Minitech, actually I couldn't find Visible in the form's designer, still can't, however if I'd just thought a little longer before asking the question my solution was simple, and in this case perfectly adequate... Just have the program run in Windows Mode Minimised.
I shall remember the 'Me.Shown' technique, thanks for that, I'm pretty sure I've seen examples of that quite often without realising it.
Poppa.
Along with the sunshine there has to be a little rain sometime.
-
Jan 1st, 2012, 08:22 PM
#7
Re: Me.Hide
A Windows service may be the more appropriate option but you may also like to follow the CodeBank link in my signature and check out my Formless Tray App thread, which demonstrates how to create a Windows Forms app that doesn't immediately display a main form.
The Visible property of the form is not included in the Properties window because it wouldn't make sense to do so. All forms are not visible until you call Show/ShowDialog and then they are visible. It's only after they have become visible for the first time that the Visible property becomes relevant, which is why calling Hide in the Load event handler, which is executed before the form becomes visible for the first time, has no effect.
-
Jan 2nd, 2012, 04:36 AM
#8
Re: Me.Hide
Or if it's procedural (runs through then exits)... turn off the framework ... make a class with a public shared sub main and select that as the startup object.
Kris
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|