日期:2014-05-18 浏览次数:20973 次
//最小化 → 正常 private void MinimizedToNormal() { this.Visible = true; this.WindowState = FormWindowState.Normal; 显示ToolStripMenuItem.Text = "隐藏窗口"; } //正常 → 最小化 private void NormalToMinimized() { this.WindowState = FormWindowState.Minimized; this.Visible = false; 显示ToolStripMenuItem.Text = "显示窗口"; } //界面点击X关闭后 取消关闭 最小化 private void MainForm_FormClosing(object sender, FormClosingEventArgs e) { this.NormalToMinimized(); e.Cancel = true; } //双击右下角图标时 会调用的notifyIcon控件的鼠标双击事件 private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { if (this.WindowState == FormWindowState.Minimized)//当窗口是最小化时。 { this.MinimizedToNormal(); } else if (this.WindowState == FormWindowState.Normal)//当窗口是最大化时。 { this.NormalToMinimized(); } } }
------解决方案--------------------
第一个功能我自己是这样的,不知道有没有更好的办法。同求。
//窗体 鼠标拉动 [DllImport("user32.dll")] public static extern bool ReleaseCapture(); [DllImport("user32.dll")] public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam); public const int WM_SYSCOMMAND = 0x0112; public const int SC_MOVE = 0xF010; public const int HTCAPTION = 0x0002; //界面MouseDown事件 private void Form1_MouseDown(object sender, MouseEventArgs e) { ReleaseCapture(); SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0); } //界面MouseMove事件 private void Form1_MouseMove(object sender, MouseEventArgs e) { if (this.Location.X < 0) { this.Location = new Point(0, this.Location.Y); } if (this.Location.X > System.Windows.Forms.SystemInformation.WorkingArea.Width - this.Size.Width) { this.Location = new Point(System.Windows.Forms.SystemInformation.WorkingArea.Width - this.Size.Width, this.Location.Y); } if (this.Location.Y > System.Windows.Forms.SystemInformation.WorkingArea.Height - this.Size.Height) { this.Location = new Point(this.Location.X, System.Windows.Forms.SystemInformation.WorkingArea.Height - this.Size.Height); } }
------解决方案--------------------
NotifyIcon控件解决
------解决方案--------------------
网上很多 窗体抖动的代码!