|
-
Nov 19th, 2003, 01:20 PM
#1
Thread Starter
Fanatic Member
Why does VB.NET have to be so iritating? [RESOLVED]
Hey,
VB.NET has become so iritating! I can't do anything simple now without having to do something advanced!
My problem is, I need an application which loads invisible. I have the NotifyIcon control sorted out, but the form that it links with I need to not appear when you start the application.
How can I do this?
I can't even choose Visible = False at design time in the forms properties, wheres it gone? Thats bloody stupid...
And an inprofessional way of doing it, like setting a code for like:
VB Code:
Private Sub frmSettings_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim frmSettings As New Form
frmSettings.Visible = False
End Sub
Is that the right way to do it anyway even though it doesnt work? Or should it be
VB Code:
Private Sub frmSettings_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
frmSettings.ActiveForm.Visible = False
End Sub
I don't even know something simple like that! VB6 is so much simpler, why have they made it so stupid?
Anyway, please help me out here! Like i said, i need my dam Startup form to not be visible when my application loads, I just need the NotifyIcon to appear on the taskbar instead. (For those who dont know what a NotifyIcon is, its the icon you get in the taskbar at the bottom right, usually double clicking it makes the app visible, like MSN Messenger)
Thanks for the help! Its appreciated.
Last edited by LITHIA; Nov 21st, 2003 at 03:44 PM.
-
Nov 19th, 2003, 01:42 PM
#2
I wonder how many charact
So really you don't want to set your startup object to a Form. What I mean is... you don't want to use that code in your form_Load event.
You want to start your program in a Main Sub.
Then, when you choose to show your form, then call it from your Main Sub.
You are right though, there is definitely something stupid afoot here.
-
Nov 19th, 2003, 01:47 PM
#3
Thread Starter
Fanatic Member
yeah i was thinkin about that. I tryed putting a Sub Main() in a module but that went 'hey wire'...
The only prob tho, how can I link to an object on that form?
If I am starting my project from a Sub Main() in say a module or class, how am to make an object on frmSettings visible?
When I tryed it, the application quit itself as soon as it opened.
Thanks for help
-
Nov 19th, 2003, 01:47 PM
#4
Junior Member
so you want code on a form to fire, but you dont want the cform to show??
Why not load a module?
What your asking is akin to "Why is it so hard to order double cheese and pepperoni on a hamburger?"
.....it just doesn't come that way.
anyway, make a module set it as the startup
tal
-
Nov 19th, 2003, 01:55 PM
#5
I used to hear people say VB6 teaches bad coding practices and I always thought they were full of ****, but this is an example. VB6 doesn't teach us to use form instances since all VB6 forms are essentially shared by default. I agree with what has already been said just start from the a Sub Main. You don't need a form to use the NotifyIcon object you can use it right from Sub Main. I mean why create a form you don't want to show. Although if you still want to use the NotifiyIcon from the form without showing it just do this:
VB Code:
Public Sub main()
Dim frm As New frmSettings()
'use forms notifyicon
frm.NotifyIcon1.Visible = True
'you will need something here to keep the thread open
frm.NotifyIcon1.Visible = False
End Sub
The reason that when you tried it it just closed right away is because it finished all its processing. You will need to right some code to wait for whatever it is you are waiting for or hold the thread open.
-
Nov 19th, 2003, 02:02 PM
#6
Thread Starter
Fanatic Member
thanks, that sounds alot better - and more efficient too.
I agree with you Edneeis, I've always been using Forms to execute code even if they never become visible.
It is bad practice and I understand why vb.net has prevented you from doing that - although it would have been nice if you still could just incase.
Thanks again, I'll try. But I am not sure exactly about the:
'you will need something here to keep the thread open
what am I going to put there? Even if its a waste, I dont want the app to close unless you specify it to.
Thanks
-
Nov 19th, 2003, 02:07 PM
#7
What is it the app does? I mean how is it the user is to interact with it?
Typically a form is shown which holds the thread open because it is waiting for user interaction. How will user interaction be done in your app. You might just have to endlessly loop to keep the thread open.
-
Nov 19th, 2003, 02:12 PM
#8
Frenzied Member
In the form loading event, try Me.Hide() or Me.Visible = False
-
Nov 19th, 2003, 02:13 PM
#9
Thread Starter
Fanatic Member
it acts like MSN Messenger, its got code and api's running (soon hopefully) in the background, if i can get those to work soon.
In my other thread, i got some code, its:
VB Code:
Private Shared WM_QUERYENDSESSION As Integer = &H11
Private Shared systemShutdown As Boolean = False
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
If m.Msg = WM_QUERYENDSESSION Then
MessageBox.Show("queryendsession: this is a logoff, shutdown, or reboot")
systemShutdown = True
End If
' If this is WM_QUERYENDSESSION, the closing event should be fired in the base WndProc
MyBase.WndProc(m)
End Sub 'WndProc
Private Sub Form1_Closing(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
If (systemShutdown) Then
' reset the variable since they may cancel the shutdown
systemShutdown = False
If (DialogResult.Yes = _
MessageBox.Show("My application", "Would you care to save your work before logging off?", MessageBoxButtons.YesNo)) Then
e.Cancel = True
Else
e.Cancel = False
End If
End If
End Sub
from the MSDN library, looks good to me!
Cya
-
Nov 19th, 2003, 02:15 PM
#10
Thread Starter
Fanatic Member
Originally posted by DevGrp
In the form loading event, try Me.Hide() or Me.Visible = False
sorry? thought we already settled somet like that wont work or be the best way. We using a module now
-
Nov 19th, 2003, 02:28 PM
#11
So do you have this resolved then or are we still working on keeping the thread open?
Also since you aren't showing a form then there I believe there is no handle which means I don't think your api calls will work (until the form has been shown). I'm not sure on that you'll need to test it. Right now the form would be waiting for system shutdown, but the waiting part would only be accomplished if it is shown then hidden because if it isn't created it isn't there to wait. Here is an example of looping to hold the thread open, although I think you'll need to move your APIs to the module.
VB Code:
Module Module1
Public looping As Boolean = True
Public Sub Main()
Dim frm As New Form3
frm.NotifyIcon1.Visible = True
Do While looping
'to exit the application you will need to set Module1.looping to False
Threading.Thread.CurrentThread.Sleep(500)
Application.DoEvents()
Loop
frm.NotifyIcon1.Visible = False
End Sub
End Module
-
Nov 21st, 2003, 10:30 AM
#12
Thread Starter
Fanatic Member
Thanks, that works great. Ive got my program to stay open and have the notify icon work good!
All I need to do now is get some code working to detect if the computer trys to shutdown and prevent it or accept it.
http://www.vbforums.com/showthread.p...hreadid=268554
Thats my post I have on it, I would appreciate it if you could take a look, its not resolved yet.
Thanks again
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
|