当我将鼠标悬停在它上面时,C#TaskBar项目会消失

时间:2010-11-22 10:51:34

标签: c# taskbar

有没有人知道为什么当我运行程序时,单击任务栏项打开小文本输入区域,图标一旦到达就消失了!

非常感谢

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

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

        private void button1_Click(object sender, EventArgs e)
        {
        }

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

        private void Form1_Resize(object sender, System.EventArgs e)
        {
            if (FormWindowState.Minimized == WindowState)
            {
                Hide();
            }
        }

        private void notifyIcon1_DoubleClick(object sender, System.EventArgs e)
        {
            var screen = Screen.PrimaryScreen;
            this.Left = screen.WorkingArea.Right - this.Width;
            this.Top = screen.WorkingArea.Bottom - this.Height;

            Application.Run();
        }

        private void searchToolStripMenuItem_Click(object sender, EventArgs e)
        {
        }

        private void quitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Close();
        } 
    }
}

编辑:我不确定这是否有帮助,但是为了使应用程序不打开表单我改变了主要方法

Application.run(new form1())

new form1()

1 个答案:

答案 0 :(得分:1)

Application.Run用于运行Windows窗体应用程序

static void Main()
{
    Application.EnableVisualStyles();
    Application.SetCompatibleTextRenderingDefault(false);
    Application.Run(new Form1());
}

当您删除行Application.Run(new Form1());时,您的应用程序刚刚启动并调用Main(),然后关闭它,因为它已完成它的工作。

问题是您删除Application.Run(new Form1()); ??

的原因