我想实现QQ那样 窗体拖到边缘可以自动隐藏 鼠标放上去可以显示这些功能已经实现可就是点击最小化以后 不能够还原了 这是什么问题啊!

解决方案 »

  1.   

    QQ 窗口 的 最小化 与关闭,都一样的,你意思是不是 像QQ一样 最小化与关闭,都消失在任务栏中,之后 点击,托盘 后 还原窗口呢?如果想   点击,托盘 后 还原窗口, 最小化与关闭时 用隐藏窗口就可以了,    this.Hide();
    点击,托盘 后 还原窗口 就显示窗口   this.Show();  我的 农场园丁 就是这样的,不知道,你是不是要这样呢?
      

  2.   

    如果希望最小化到托盘,点击托盘图标激活窗口,右键图标提示退出程序的话,需要notifyIcon控件。代码如下:
    public Form1()
            {
                InitializeComponent();                      
                //初始化托盘程序的各个要素 
                  Initializenotifyicon(); 
                m_bShowWnd = true;
                closingFlag = false;
            }private ContextMenu notifyiconMnu = new ContextMenu();
    private void Initializenotifyicon()
            {
                //定义一个MenuItem数组,并把此数组同时赋值给ContextMenu对象 
                MenuItem[] mnuItms = new MenuItem[1];
                mnuItms[0] = new MenuItem();
                mnuItms[0].Text = "退出";
                mnuItms[0].Click += new System.EventHandler(this.ExitSelect);
                mnuItms[0].DefaultItem = true;            notifyiconMnu = new ContextMenu(mnuItms);
                notifyIcon1.ContextMenu = notifyiconMnu;
                notifyIcon1.BalloonTipText = "Hello World!";
                notifyIcon1.BalloonTipTitle = "提示:";
                //为托盘程序加入设定好的ContextMenu对象         }
    public void ExitSelect(object sender, System.EventArgs e)
            {
               closingFlag = true;
                //隐藏托盘程序中的图标 
                notifyIcon1.Dispose();
                //关闭系统 
                Application.Exit();
            } 
     private void Form1_FormClosing(object sender, System.ComponentModel.CancelEventArgs e)
            {
                if(closingFlag == false)
                    e.Cancel = true;
                this.notifyIcon1.Visible = true;
                this.Hide();
                m_bShowWnd = false;
                notifyIcon1.ShowBalloonTip(10);        }        private void notifyIcon1_MouseClick(object sender, MouseEventArgs e)
            {
                if (e.Button == MouseButtons.Left)
                {
                    if (m_bShowWnd == true)   //根据窗口的显示和隐藏设置Trayico对象的显示 
                    {
                        this.Hide();
                        this.notifyIcon1.Visible = true;
                        m_bShowWnd = false;
                    }
                    else
                    {
                        this.Show();
                        this.notifyIcon1.Visible = true;
                        m_bShowWnd = true;
                    }
                    if (this.WindowState == FormWindowState.Minimized)
                        this.WindowState = FormWindowState.Normal;                this.Activate();
                }
            }