123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262 |
- using PTMedicalInsurance;
- 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;
- using static HaErBinMI.Forms.ToRecord.Helper.DropHelper;
- namespace WinFrom1
- {
- public partial class ModelFrom : Form
- {
- public ModelFrom()
- {
- InitializeComponent();
- }
-
- private void ModelFrom_SizeChanged(object sender, EventArgs e)
- {
- if (this.WindowState != FormWindowState.Maximized)
- {
-
-
- }
- }
- private void ModelFrom_Load(object sender, EventArgs e)
- {
-
- this.Left = Screen.PrimaryScreen.WorkingArea.Width / 2 - this.Width / 2;
- this.Top = Screen.PrimaryScreen.WorkingArea.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 HTLEFT = 10;
- const int HTRIGHT = 11;
- const int HTTOP = 12;
- const int HTTOPLEFT = 13;
- const int HTTOPRIGHT = 14;
- const int HTBOTTOM = 15;
- const int HTBOTTOMLEFT = 0x10;
- const int 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)HTTOPLEFT;
- else if (vPoint.Y >= ClientSize.Height - 5)
- m.Result = (IntPtr)HTBOTTOMLEFT;
- else m.Result = (IntPtr)HTLEFT;
- else if (vPoint.X >= ClientSize.Width - 5)
- if (vPoint.Y <= 5)
- m.Result = (IntPtr)HTTOPRIGHT;
- else if (vPoint.Y >= ClientSize.Height - 5)
- m.Result = (IntPtr)HTBOTTOMRIGHT;
- else m.Result = (IntPtr)HTRIGHT;
- else if (vPoint.Y <= 2)
- m.Result = (IntPtr)HTTOP;
- else if (vPoint.Y >= ClientSize.Height - 5)
- m.Result = (IntPtr)HTBOTTOM;
- break;
- default:
- base.WndProc(ref m);
- break;
- }
- }
- #endregion
- #region 下拉框自动选择
-
-
-
-
-
- public void ComBoxChoose(Dictionary<string, string> data, ComboBox comBox,bool drop)
- {
- comBox.Items.Clear();
- List<ComboBoxItem> temp = new List<ComboBoxItem>();
- foreach (var item in data)
- {
-
- if (item.Value.Contains(comBox.Text))
- {
- ComboBoxItem com = new ComboBoxItem();
- com.Text = item.Value;
- com.Value = item.Key;
- temp.Add(com);
- }
- }
- if (temp.Count < 1)
- {
-
- ComboBoxItem zero = new ComboBoxItem();
- zero.Text = "";
- zero.Value = "";
- temp.Add(zero);
- }
- try
- {
- comBox.Items.AddRange(temp.ToArray());
- comBox.SelectionStart = comBox.Text.Length;
- Cursor = Cursors.Default;
- if (drop)
- {
- comBox.DroppedDown = true;
- }
- }
- catch (Exception ee)
- {
- comBox.SelectedIndex = -1;
- }
- }
- #endregion
- }
- }
|