开发者

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:

Hide Form on startup in c#

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 :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜