using MaiMuControl.Device; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace GeBoShi.UIKits.MaiMuMenu { public partial class UITitel_LT : UserControl { public MenuStrip UserMenuStrip = null; private Form _fartherForm = null; public Form FatherForm { get { return _fartherForm; } set { if ( value != null) { _original_Height = value.Height; _original_Width = value.Width; _original_Top = value.Top; _original_Left = value.Left; } _fartherForm = value; } } private int _original_Height; private int _original_Width; private int _original_Top; private int _original_Left; private int _windowsState; public UITitel_LT() { InitializeComponent(); this.Dock = DockStyle.Top; if(UserMenuStrip == null) this.UimenuStrip.Visible = false; else this.UimenuStrip = UserMenuStrip; } public void ShowMenu() { if (UserMenuStrip == null) this.UimenuStrip.Visible = false; else { UserMenuStrip.AutoSize = false; UserMenuStrip.Height = this.Height; this.tableLayoutPanel1.Controls.Remove( this.UimenuStrip); //this.UimenuStrip = UserMenuStrip; //this.UimenuStrip.Visible = true; this.tableLayoutPanel1.Controls.Add(UserMenuStrip, 1, 0); UserMenuStrip.Renderer = new MaiMuMenuRender(); } } public void ShowContrlBox(bool min, bool max, bool close, bool size = false) { this.tsbMin.Visible = min; this.tsbMax.Visible = max; this.tsbClose.Visible = close; this.tsbSize.Visible = size; } private void tsbSize_Click(object sender, EventArgs e) { } private void tsbMin_Click(object sender, EventArgs e) { FatherForm.WindowState = FormWindowState.Minimized; _windowsState = (int)FormWindowState.Minimized; } private void tsbMax_Click(object sender, EventArgs e) { //if (FatherForm.WindowState != FormWindowState.Maximized) if((FatherForm.Width < SystemInformation.WorkingArea.Width)&&(FatherForm.Height < SystemInformation.WorkingArea.Height)) { _windowsState = (int)FormWindowState.Maximized; //FatherForm.WindowState = FormWindowState.Maximized; FatherForm.Top = 0; FatherForm.Left = 0; FatherForm.Width = SystemInformation.WorkingArea.Width; FatherForm.Height = SystemInformation.WorkingArea.Height; } else { _windowsState = (int)FormWindowState.Normal; //FatherForm.WindowState = FormWindowState.Normal; FatherForm.Top = (SystemInformation.WorkingArea.Height - _original_Height) / 2; FatherForm.Left = (SystemInformation.WorkingArea.Width - _original_Width) / 2; FatherForm.Width = _original_Width; FatherForm.Height = _original_Height; //FatherForm.StartPosition = FormStartPosition.CenterScreen; } } private void tsbClose_Click(object sender, EventArgs e) { FatherForm.Close(); } #region 鼠标按住拖动界面 [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; private void UITitel_MouseDown(object sender, MouseEventArgs e) { ReleaseCapture(); SendMessage(FatherForm.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0); } private void tableLayoutPanel1_MouseDown(object sender, MouseEventArgs e) { ReleaseCapture(); SendMessage(FatherForm.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0); } private void pictureBox2_MouseDown(object sender, MouseEventArgs e) { ReleaseCapture(); SendMessage(FatherForm.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0); } #endregion private void skinToolStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e) { } #region 界面放大缩小 bool isMouseDown = false; //表示鼠标当前是否处于按下状态,初始值为否 Point size_change = Point.Empty; private void tsbSize_MouseDown(object sender, MouseEventArgs e) { isMouseDown = true; FatherForm.Cursor = Cursors.SizeNESW; this.Cursor = Cursors.SizeNESW; size_change = e.Location; } private void tsbSize_MouseMove(object sender, MouseEventArgs e) { ResizeWindow(e); } private void tsbSize_MouseUp(object sender, MouseEventArgs e) { isMouseDown = false; FatherForm.Cursor = Cursors.Default; this.Cursor = Cursors.Default; } private void ResizeWindow(MouseEventArgs e) { //这个判断很重要,只有在鼠标按下时才能拖拽改变窗体大小,如果不作判断,那么鼠标弹起和按下时,窗体都可以改变 if (!isMouseDown) return; //MousePosition的参考点是屏幕的左上角,表示鼠标当前相对于屏幕左上角的坐标this.left和this.top的参考点也是屏幕,属性MousePosition是该程序的重点 if (FatherForm.Cursor == Cursors.SizeNESW) { //此行代码在mousemove事件中已经写过,在此再写一遍,并不多余,一定要写 this.Cursor = Cursors.SizeNESW; //下面是改变窗体宽和高的代码,不明白的可以仔细思考一下 FatherForm.Width = FatherForm.Width + (e.Location.X - size_change.X); FatherForm.Top = FatherForm.Top + (e.Location.Y - size_change.Y); FatherForm.Height = FatherForm.Height - (e.Location.Y - size_change.Y) ; this.Refresh(); } //即使鼠标按下,但是不在窗口右和下边缘,那么也不能改变窗口大小 else this.Cursor = Cursors.Arrow; } private void tsbSize_MouseLeave(object sender, EventArgs e) { isMouseDown = false; FatherForm.Cursor = Cursors.Default; this.Cursor = Cursors.Default; } #endregion } }