在c#中启动时隐藏表单

时间:2011-07-11 16:07:37

标签: c# forms tooltip hide

我尝试在启动时隐藏c#中的表单...

我想要的是一个任务栏工具提示程序,如下所示:

enter image description here

但我尝试不同的东西,但我无法隐藏表格!

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);
     }

}

我希望有人可以帮助我: - )

2 个答案:

答案 0 :(得分:3)

看看这个:http://www.vbforums.com/showthread.php?t=637483而不是做你正在做的事情。

此外,问题是当表单加载时它还不可见。处理Shown事件而不是Load事件。

答案 1 :(得分:2)

之前我做了类似的事情(我甚至可能使用上面的链接作为参考),但这是我执行它的方式。

在您的main方法(通常是program.cs)中,您希望代码看起来像这样....

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

在你的createIcon类中,你将拥有这样的东西:

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
}

这应该可以帮助您入门,您可以将其更改为最适合您:)