0

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()
ChrisF
  • 134,786
  • 31
  • 255
  • 325
tom
  • 4,911
  • 11
  • 37
  • 39

1 Answers1

1

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

  • because of this http://stackoverflow.com/questions/70272/single-form-hide-on-startup – tom Nov 22 '10 at 12:07