Results 1 to 4 of 4

Thread: [RESOLVED] Hide on minmize

  1. #1

    Thread Starter
    Fanatic Member Crash893's Avatar
    Join Date
    Dec 2005
    Posts
    930

    Resolved [RESOLVED] Hide on minmize

    Hi all

    I'm finishing up a small personnel project and I'm having some trouble with the "showintaskbar= false" property of the form



    as you can see when is the show in task bar to false it does indeed not show up in the task bar but i get a "mdi" ish minimized window right above the task bar.


    to get around this i tried making a sub called "open_close"

    c# Code:
    1. private void open_close()
    2.         {
    3.  
    4.             if (WindowState != FormWindowState.Normal)
    5.             {
    6.                 Show();
    7.                 WindowState = FormWindowState.Normal;
    8.             }
    9.             else
    10.             {
    11.                 Hide();
    12.                 WindowState = FormWindowState.Minimized;
    13.             }
    14.         }


    The open_close is triggered by either a double click on the notifyicon1 or a form1 resize

    The problem i am running into two problems as side effects

    1) since there is no way i know of to capture the specific form minimize event i can only use form resize so if i resize the form manually (using the mouse) i still get the same event triggering as if i hit minimize

    2) the form still blinks down at the bottom before it hides so its a little distracting.


    so my questions is:

    Is there a better way to intercept the minimize button on the for???

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

    Re: Hide on minmize

    Handle the SizeChanged event.
    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

  3. #3

    Thread Starter
    Fanatic Member Crash893's Avatar
    Join Date
    Dec 2005
    Posts
    930

    Re: Hide on minmize

    Quote Originally Posted by jmcilhinney
    Handle the SizeChanged event.

    this is what I have, the problem if i resize the form ( make it wider or smaller by grabbing the border) it triggers the same event as if i hit the minimize button.



    private void Form1_SizeChanged(object sender, EventArgs e)
    {
    open_close();
    }

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

    Re: Hide on minmize

    I didn't say that you weren't supposed to test the WindowState property. It's really very simple:
    C# Code:
    1. private void Form1_SizeChanged(object sender, EventArgs e)
    2. {
    3.     this.Visible = (this.WindowState != FormWindowState.Minimized);
    4. }
    Now if the form is minimise it is not visible and if it's not minimised it is visible. If you want the form restored when the user double-clicks the tray icon then you simply set the WindowState to Normal in the DoubleClick event handler of the NotifyIcon. That will cause the SizeChanged event to be raised and that will cause the visiblity of the form to change.
    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

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