none
How to judge my winform applicaiton start with double click or register

    Question

  • I added my winform application (C#) to register and it could started when my computer reboot. But I want that: when my application reboot and my application need to be started in tray and if I double click it, it will start normally not in tray.

    how to implement it.


    • Edited by qing__ Thursday, February 08, 2018 12:45 AM
    Thursday, February 08, 2018 12:44 AM

Answers

  • When you add the corresponding definitions for automatic start, maybe add some special parameter to command line, for example: “C:\MyProgram.exe /myparameter”.

    Then you can check if the parameter is present using Environment.GetCommandLineArgs.



    • Edited by Viorel_MVP Thursday, February 08, 2018 6:53 PM
    • Marked as answer by qing__ Friday, February 09, 2018 12:41 AM
    Thursday, February 08, 2018 6:51 PM

All replies

  • Hi qing,

    >>But I want that: when my application reboot and my application need to be started in tray and if I double click it, it will start normally not in tray.

    You can use a notifyIcon control to do it, and make sure you set an icon for it first, otherwise you can not find the app when you hide it to the tray:

    Then the code:

            private void Form1_Load(object sender, EventArgs e)
            {
                WindowState = FormWindowState.Minimized;
            }       
    
            private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
            {
                if (WindowState == FormWindowState.Minimized)
                {   
                    WindowState = FormWindowState.Normal;
                    this.Activate();
                    this.ShowInTaskbar = true;
                    notifyIcon1.Visible = false;
                }
            }
    
            private void Form1_SizeChanged(object sender, EventArgs e)
            {
                if (WindowState == FormWindowState.Minimized)
                {
                    this.ShowInTaskbar = false;
                    notifyIcon1.Visible = true;
                }
            }

    Regards,

    Frankie


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, February 08, 2018 7:35 AM
    Moderator
  • I think you could not understand my means. I could implement your function in my side.

    I repeat my idea again, if I double click my application, it must display normally, this is first, your resolution could not implement this.

    I my computer reboot, it will start in tray.

    how to judge my application started with which type?

    Thursday, February 08, 2018 7:45 AM
  • Hi,

    >>if I double click my application, it must display normally, this is first, your resolution could not implement this.

    Why do you say that it did not implement? My code can achieve your purpose that double clicking the app in the tray then the app will display normally, have you tried it?

            

    //double click to display the app normally

    private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e) { if (WindowState == FormWindowState.Minimized) { WindowState = FormWindowState.Normal; this.Activate(); this.ShowInTaskbar = true; notifyIcon1.Visible = false; } }

    >>I my computer reboot, it will start in tray.

    This code did it:

            private void Form1_Load(object sender, EventArgs e)
            {
                WindowState = FormWindowState.Minimized;
            } 

    >>how to judge my application started with which type?

            private void Form1_Load(object sender, EventArgs e)
            {
                if (WindowState == FormWindowState.Minimized)
                {
                    //minimized to tray
                }
                if (WindowState == FormWindowState.Normal)
                {
                    //display normally
                }
            }
     

    Regards,

    Frankie


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, February 08, 2018 8:14 AM
    Moderator
  • When you add the corresponding definitions for automatic start, maybe add some special parameter to command line, for example: “C:\MyProgram.exe /myparameter”.

    Then you can check if the parameter is present using Environment.GetCommandLineArgs.



    • Edited by Viorel_MVP Thursday, February 08, 2018 6:53 PM
    • Marked as answer by qing__ Friday, February 09, 2018 12:41 AM
    Thursday, February 08, 2018 6:51 PM

  • Hi Viorel_

    you are right, thank you very much. :)

    Friday, February 09, 2018 12:42 AM