Results 1 to 8 of 8

Thread: Me.Hide

  1. #1

    Thread Starter
    PowerPoster Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Bottesford, North Lincolnshire, England.
    Posts
    2,500

    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.

  2. #2
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    3,826

    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

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

  3. #3

    Thread Starter
    PowerPoster Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Bottesford, North Lincolnshire, England.
    Posts
    2,500

    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.

  4. #4
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    3,826

    Re: Me.Hide

    Quote Originally Posted by Poppa Mintin View Post
    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

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

  5. #5
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    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.

  6. #6

    Thread Starter
    PowerPoster Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Bottesford, North Lincolnshire, England.
    Posts
    2,500

    Re: Me.Hide

    Quote Originally Posted by minitech View Post
    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.

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  8. #8
    PowerPoster i00's Avatar
    Join Date
    Mar 2002
    Location
    1/2 way accross the galaxy.. and then some
    Posts
    2,390

    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
  •  



Click Here to Expand Forum to Full Width