123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- 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 BurronModel.TestModel
- {
- public partial class ModelFrom : Form
- {
- public ModelFrom()
- {
- InitializeComponent();
- }
- private void ModelFrom_Load(object sender, EventArgs e)
- {
-
-
-
- this.Left = Screen.PrimaryScreen.Bounds.Width / 2 - this.Width / 2;
- this.Top = Screen.PrimaryScreen.Bounds.Height / 2 - this.Height / 2;
- #region 窗体自适应调用
- this.Resize += new EventHandler(FormResize);
- X = this.Width;
- Y = this.Height;
- SetConSize(this);
- FormResize(new object(), new EventArgs());
- #endregion
- #region 双缓冲
- this.DoubleBuffered = true;
- SetStyle(ControlStyles.UserPaint, true);
- SetStyle(ControlStyles.AllPaintingInWmPaint, true);
- SetStyle(ControlStyles.DoubleBuffer, true);
-
-
- #endregion
-
-
- }
- #region 窗体及控件自适应
- private float X;
- private float Y;
- private void SetConSize(Control cons)
- {
- foreach (Control con in cons.Controls)
- {
- con.Tag = con.Width + ":" + con.Height + ":" + con.Left + ":" + con.Top + ":" + con.Font.Size;
- if (con.Controls.Count > 0)
- SetConSize(con);
- }
- }
- private void setControls(float newx, float newy, Control cons)
- {
- foreach (Control con in cons.Controls)
- {
- string[] mytag = con.Tag.ToString().Split(new char[] { ':' });
- float a = Convert.ToSingle(mytag[0]) * newx;
- con.Width = (int)a;
- a = Convert.ToSingle(mytag[1]) * newy;
- con.Height = (int)(a);
- a = Convert.ToSingle(mytag[2]) * newx;
- con.Left = (int)(a);
- a = Convert.ToSingle(mytag[3]) * newy;
- con.Top = (int)(a);
- Single currentSize = Convert.ToSingle(mytag[4]) * Math.Min(newx, newy);
- con.Font = new Font(con.Font.Name, currentSize, con.Font.Style, con.Font.Unit);
- if (con.Controls.Count > 0)
- {
- setControls(newx, newy, con);
- }
- }
- }
- private void FormResize(object sender, EventArgs e)
- {
- float newx = (this.Width) / X;
- float newy = this.Height / Y;
- setControls(newx, newy, this);
-
- }
- #endregion
- #region 减少窗体变化带来的频闪
- protected override CreateParams CreateParams
- {
- get
- {
- CreateParams cp = base.CreateParams;
-
-
- if (!DesignMode)
- {
- cp.ExStyle |= 0x02000000;
- return cp;
- }
- return cp;
- }
- }
-
-
-
-
-
-
- #endregion
- #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);
- private void menuStrip1_MouseDown(object sender, MouseEventArgs e)
- {
- if (e.Clicks == 1)
- {
-
- if (e.Button == MouseButtons.Left)
- {
- ReleaseCapture();
-
- SendMessage(this.Handle, 0xA1, 0x02, 0);
- }
- }
- }
-
- const int Guying_HTLEFT = 10;
- const int Guying_HTRIGHT = 11;
- const int Guying_HTTOP = 12;
- const int Guying_HTTOPLEFT = 13;
- const int Guying_HTTOPRIGHT = 14;
- const int Guying_HTBOTTOM = 15;
- const int Guying_HTBOTTOMLEFT = 0x10;
- const int Guying_HTBOTTOMRIGHT = 17;
- protected override void WndProc(ref Message m)
- {
- switch (m.Msg)
- {
- case 0x0084:
- base.WndProc(ref m);
- Point vPoint = new Point((int)m.LParam & 0xFFFF,
- (int)m.LParam >> 16 & 0xFFFF);
- vPoint = PointToClient(vPoint);
- if (this.WindowState != FormWindowState.Normal)
- break;
- if (vPoint.X <= 5)
- if (vPoint.Y <= 5)
- m.Result = (IntPtr)Guying_HTTOPLEFT;
- else if (vPoint.Y >= ClientSize.Height - 5)
- m.Result = (IntPtr)Guying_HTBOTTOMLEFT;
- else m.Result = (IntPtr)Guying_HTLEFT;
- else if (vPoint.X >= ClientSize.Width - 5)
- if (vPoint.Y <= 5)
- m.Result = (IntPtr)Guying_HTTOPRIGHT;
- else if (vPoint.Y >= ClientSize.Height - 5)
- m.Result = (IntPtr)Guying_HTBOTTOMRIGHT;
- else m.Result = (IntPtr)Guying_HTRIGHT;
- else if (vPoint.Y <= 2)
- m.Result = (IntPtr)Guying_HTTOP;
- else if (vPoint.Y >= ClientSize.Height - 5)
- m.Result = (IntPtr)Guying_HTBOTTOM;
- break;
- default:
- base.WndProc(ref m);
- break;
- }
- }
- #endregion
- }
- }
|