简体   繁体   中英

Hide Form on startup in c#

i try to hide the form in c# on startup...

what i want is a Taskbar Tooltip Programm, like this:

在此处输入图像描述

But i try different things but i cannot hide the form!

public partial class Form1 : Form
{
     public Form1()
    {
        InitializeComponent();
    }

     private void Form1_Load(object sender, EventArgs e)
     {
         this.Visible = false;
     }

     private void notifyIcon1_MouseDoubleCLick(object sender, MouseEventArgs e)
     {
         notifyIcon1.ShowBalloonTip(500, "Title", "Tip text", ToolTipIcon.Info);
     }

}

I hope someone can help me:-)

Take a look at this: http://www.vbforums.com/showthread.php?t=637483 instead of doing what you're doing.

Also, the problem is that when the form loads it's not visible yet. Handle the Shown event instead of the Load event.

I did something similiar to this before (I might have even used the link above as a reference), but here's how I executed it.

In your main method (program.cs usually) you want your code to look something like this....

Application.EnableVisualStyles();
createIcon cIcon = createIcon.getIconObject();
Application.Run();
cIcon = null;

Inside your createIcon class you will have something to this extent:

private static readonly createIcon cIcon = new createIcon();
private NotifyIcon notify;
private ContextMenuStrip contextMenu = new ContextMenuStrip();
private bool IsDisposing = false;

public static createIcon getIconObject()
{
      return cIcon;
}

private createIcon()
{
            ToolStripMenuItem ssItem = new ToolStripMenuItem("Open", null, new EventHandler(notify_DoubleClick));
            contextMenu.Items.Add(ssItem);
            ssItem = new ToolStripMenuItem("Settings",null, new EventHandler(settings_Click));
            contextMenu.Items.Add(ssItem);
            ssItem = new ToolStripMenuItem("About", null, new EventHandler(about_Click));
            contextMenu.Items.Add(ssItem);
            ssItem = new ToolStripMenuItem("Exit", null, new EventHandler(Menu_OnExit));
            contextMenu.Items.Add(ssItem);

            notify = new NotifyIcon();
            notify.Icon = "Icon.ICO";
            notify.Text = "Name";
            notify.ContextMenuStrip = contextMenu;
            notify.DoubleClick += new EventHandler(notify_DoubleClick);
            notify.Visible = true;
}

public void Dispose()
{
     if (!IsDisposing)
     {
         IsDisposing = true;
     }
}

private void notify_DoubleClick(object sender, EventArgs e)
{
    .... code here
}

This should help you get started and you can change it to work the best for you:)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM