Results 1 to 12 of 12

Thread: Why does VB.NET have to be so iritating? [RESOLVED]

  1. #1

    Thread Starter
    Fanatic Member LITHIA's Avatar
    Join Date
    Dec 2002
    Location
    UK, England
    Posts
    575

    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:
    1. Private Sub frmSettings_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    2.         Dim frmSettings As New Form
    3.         frmSettings.Visible = False
    4.     End Sub

    Is that the right way to do it anyway even though it doesnt work? Or should it be

    VB Code:
    1. Private Sub frmSettings_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    2.         frmSettings.ActiveForm.Visible = False
    3.     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.

  2. #2
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    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.

  3. #3

    Thread Starter
    Fanatic Member LITHIA's Avatar
    Join Date
    Dec 2002
    Location
    UK, England
    Posts
    575
    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

  4. #4
    Junior Member
    Join Date
    Oct 2003
    Posts
    17
    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

  5. #5
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    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:
    1. Public Sub main()
    2.         Dim frm As New frmSettings()
    3.         'use forms notifyicon
    4.         frm.NotifyIcon1.Visible = True
    5.  
    6.         'you will need something here to keep the thread open
    7.  
    8.         frm.NotifyIcon1.Visible = False
    9.     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.

  6. #6

    Thread Starter
    Fanatic Member LITHIA's Avatar
    Join Date
    Dec 2002
    Location
    UK, England
    Posts
    575
    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

  7. #7
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    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.

  8. #8
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    In the form loading event, try Me.Hide() or Me.Visible = False

  9. #9

    Thread Starter
    Fanatic Member LITHIA's Avatar
    Join Date
    Dec 2002
    Location
    UK, England
    Posts
    575
    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:
    1. Private Shared WM_QUERYENDSESSION As Integer = &H11
    2. Private Shared systemShutdown As Boolean = False
    3. Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
    4.     If m.Msg = WM_QUERYENDSESSION Then
    5.         MessageBox.Show("queryendsession: this is a logoff, shutdown, or reboot")
    6.         systemShutdown = True
    7.     End If
    8.     ' If this is WM_QUERYENDSESSION, the closing event should be fired in the base WndProc
    9.     MyBase.WndProc(m)
    10. End Sub 'WndProc
    11. Private Sub Form1_Closing(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
    12.     If (systemShutdown) Then
    13.     ' reset the variable since they may cancel the shutdown
    14.         systemShutdown = False
    15.         If (DialogResult.Yes = _
    16.                 MessageBox.Show("My application", "Would you care to save your work before logging off?", MessageBoxButtons.YesNo)) Then
    17.                 e.Cancel = True
    18.         Else
    19.                 e.Cancel = False
    20.         End If
    21.     End If
    22. End Sub

    from the MSDN library, looks good to me!

    Cya

  10. #10

    Thread Starter
    Fanatic Member LITHIA's Avatar
    Join Date
    Dec 2002
    Location
    UK, England
    Posts
    575
    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

  11. #11
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    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:
    1. Module Module1
    2.  
    3.     Public looping As Boolean = True
    4.  
    5.     Public Sub Main()
    6.         Dim frm As New Form3
    7.         frm.NotifyIcon1.Visible = True
    8.  
    9.         Do While looping
    10.             'to exit the application you will need to set Module1.looping to False
    11.             Threading.Thread.CurrentThread.Sleep(500)
    12.             Application.DoEvents()
    13.         Loop
    14.  
    15.         frm.NotifyIcon1.Visible = False
    16.     End Sub
    17.  
    18.  
    19. End Module

  12. #12

    Thread Starter
    Fanatic Member LITHIA's Avatar
    Join Date
    Dec 2002
    Location
    UK, England
    Posts
    575
    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
  •  



Click Here to Expand Forum to Full Width