标签:too close page nlp msi else pps new ase
一 最大化
二 最小化
三 关闭
四 点击任务栏隐藏显示
五 点击鼠标左键移动窗体
#region UI设置 最大化、最小化、关闭、鼠标移动窗口、点击任务栏切换窗口 this.pnlMin.MouseHover += new EventHandler(pnlMin_MouseMove);//最小化按钮的鼠标经过样式改变事件 this.pnlMin.MouseLeave += new EventHandler(pnlMin_MouseLeave);//最小化按钮的鼠标离开样式改变事件 this.pnlMin.Click += new EventHandler(pnlMin_Click);//最小化按钮单击事件 this.pnlMax.MouseHover += new EventHandler(pnlMax_MouseMove);//最小化按钮的鼠标经过样式改变事件 this.pnlMax.MouseLeave += new EventHandler(pnlMax_MouseLeave);//最小化按钮的鼠标离开样式改变事件 this.pnlMax.Click += new EventHandler(pnlMax_Click);//最小化按钮单击事件 this.pnlClose.MouseHover += new EventHandler(pnlClose_MouseMove);//鼠标经过关闭按钮时的样式改变 this.pnlClose.MouseLeave += new EventHandler(pnlClose_MouseLeave);//鼠标离开关闭按钮事件 this.pnlClose.Click += new EventHandler(pnlClose_Click);//关闭按钮的单击事件 this.pnlHead1.MouseDown += new MouseEventHandler(sysSet_MouseDown); //鼠标移动窗体位置 this.pnlHead1.MouseMove += new MouseEventHandler(sysSet_MouseMove);//鼠标移动窗体位置 this.pnlHead1.MouseUp += new MouseEventHandler(sysSet_MouseUp);//鼠标移动窗体位置 #endregion
#region UI设置 最大化、最小化、关闭、鼠标移动窗口、点击任务栏切换窗口 #region 单击任务栏,最小化 protected override CreateParams CreateParams //点击任务栏实现最小化与还原 { get { const int WS_MINIMIZEBOX = 0x00020000; CreateParams cp = base.CreateParams; cp.Style = cp.Style | WS_MINIMIZEBOX; // 允许最小化操作 return cp; } } #endregion #region 最小化按钮 //最小化按钮的鼠标经过改变样式事件 private void pnlMin_MouseMove(object sender, EventArgs e) { tip.SetToolTip(this.pnlMin, "最小化"); this.pnlMin.BackColor = Color.FromArgb(30, 255, 255, 255); } //最小化按钮的鼠标离开改变样式事件 private void pnlMin_MouseLeave(object sender, EventArgs e) { this.pnlMin.BackColor = Color.Transparent; } //最小化按钮的单击事件 private void pnlMin_Click(object sender, EventArgs e) { if (WindowState != FormWindowState.Minimized) { WindowState = FormWindowState.Minimized; } } #endregion #region 最大化 private void pnlMax_MouseMove(object sender, EventArgs e) { tip.SetToolTip(this.pnlMax, "最大化"); if (WindowState == FormWindowState.Maximized) { tip.SetToolTip(this.pnlMax, "恢复"); } this.pnlMax.BackColor = Color.FromArgb(30, 0, 0, 0); } //最小化按钮的鼠标离开改变样式事件 private void pnlMax_MouseLeave(object sender, EventArgs e) { this.pnlMax.BackColor = Color.Transparent; } //最小化按钮的单击事件 private void pnlMax_Click(object sender, EventArgs e) { int h = Screen.PrimaryScreen.WorkingArea.Height; int w = Screen.PrimaryScreen.WorkingArea.Width; if (WindowState == FormWindowState.Normal) { //this.MaximumSize = new Size(w, h);//设置窗体最大化为满屏 this.MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height); this.pnlMax.BackgroundImage = global::Cnwin.Apps.Properties.Resources.max; //this.tbCnt.Dock = DockStyle.Right; //this.pnlCnt.Height = h - 10; //this.pnlCnt.Width = w - 2; //this.sptCnt.Width = 260; this.pnlMax.Invalidate(); WindowState = FormWindowState.Maximized; //PnlRslt.Left = (w / 2); //sptCnt.SplitterDistance = 80; //dgvRslt.Width = w - 100; } else { this.FormBorderStyle = FormBorderStyle.None; this.pnlMax.BackgroundImage = global::Cnwin.Apps.Properties.Resources.max16; //this.pnlCnt.Height = 629; //this.pnlCnt.Width = 964; this.MaximumSize = new Size(966, 630); this.pnlMax.Invalidate(); WindowState = FormWindowState.Normal; this.Height = 656; //PnlRslt.Left = 420; //sptCnt.SplitterDistance = 80; //dgvRslt.Width = 840; //dgvRslt.Height = 452; //pnlPage.Top = 508; } //int width = 0; int clmSum = this.dgvRslt.Columns.Count; ////对于DataGridView的每一个列都调整 //for (int i = 0; i < clmSum; i++) //{ // //将每一列都调整为自动适应模式 // this.dgvRslt.AutoResizeColumn(i, DataGridViewAutoSizeColumnMode.AllCells); // //记录整个DataGridView的宽度 // width += this.dgvRslt.Columns[i].Width; //} ////判断调整后的宽度与原来设定的宽度的关系,如果是调整后的宽度大于原来设定的宽度, ////则将DataGridView的列自动调整模式设置为显示的列即可, ////如果是小于原来设定的宽度,将模式改为填充。 //if (width > this.dgvRslt.Size.Width) //{ // this.dgvRslt.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.DisplayedCells; //} //else //{ // //this.dgvRslt.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; //} ////this.MaximizedBounds = Screen.PrimaryScreen.WorkingArea; } #endregion #region 关闭按钮 //鼠标经过关闭按钮时触发样式改变 private void pnlClose_MouseMove(object sender, EventArgs e) { tip.SetToolTip(this.pnlClose, "关闭"); this.pnlClose.BackColor = Color.Red; } //鼠标离开关闭按钮触发样式改变 private void pnlClose_MouseLeave(object sender, EventArgs e) { this.pnlClose.BackColor = Color.Transparent; } protected void pnlClose_Click(object sender, EventArgs e) { FrmMonitor lg = new FrmMonitor(); lg.Dispose(); Application.Exit(); } #endregion #region 鼠标移动窗体移动 //窗体拖动 bool isMouseDown = false; Point cwpt = new Point(); //当前窗体位置 Point cmpt = new Point(); //当前鼠标的按下位置 private void sysSet_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { isMouseDown = true; cwpt = this.Location; cmpt = System.Windows.Forms.Control.MousePosition; } } private void sysSet_MouseUp(object sender, MouseEventArgs e) { isMouseDown = false; } private void sysSet_MouseMove(object sender, MouseEventArgs e) { int rangeX = 0, rangeY = 0; //计算当前鼠标光标的位移,让窗体进行相同大小的位移 if (isMouseDown) { Point pt = System.Windows.Forms.Control.MousePosition; rangeX = cmpt.X - pt.X; rangeY = cmpt.Y - pt.Y; this.Location = new Point(cwpt.X - rangeX, cwpt.Y - rangeY); } } #endregion #endregion
Winform 最小化 最大化 关闭 点击任务栏隐藏显示 点击鼠标左键移动窗体
标签:too close page nlp msi else pps new ase
原文地址:http://www.cnblogs.com/ligenyun/p/7627557.html