开发者

C# TaskBar Item disappears when I hover over it

Has anyone got any idea why when I run the program, and go to click the taskbar item to open the small text entry area the icon disappears as soon as I get to it!!!

Thanks very much

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

edit: I am not sure if this helps but to make the application not open the form I changed the main method from

Application.run(new form1())

to

new form1()


Application.Run is use to run your windows form application,

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

when you delete the line Application.Run(new Form1()); then your application just started and call Main() and after that it closed because it has finished it's work.

the question is why you delete Application.Run(new Form1());??

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜