Handle control

xiaoxiao2021-03-06  50

There is a handle that can be dragged in the STATUSBAR. When you drag it on it, you can adjust the size of the current form. How to simulate one, I have made a small control, just the effect Similarly, as in the system, I don't know, I don't know, the following is the code of the control, I don't write a comment, because I am afraid that someone laughs, huh, it is, in fact, don't write a comment:

Using system.drawing; using system.windows.forms ;. USING SYSTEM.WINDOWING;

Namespace Size_MoveCtr {///

/// Mover's summary description. /// public class sizegrip: system.windows.forms.control {private const INT WM_NCHITTEST = 0x84; private const Int wm_nclbuttondown = 0xa1;

Private const Int htclient = 1; private const Int htbottomright = 17; private system.drawing.drawing2d.graphicspath m_path;

[System.Runtime.InteropServices.dllimport ("User32.dll")] Public Static Extern Int SendMessage (INTPTR HWND, INT MSG, INTPTR WPARAM, INTPTR LPARAM);

Public sizegrip () {this.m_path = new system.drawing.drawing2d.graphicspath ();

THIS.M_PATH.StartFigure (); this.m_path.addlines (new point [] {new point (this.width, 0), new point (this.width-this.Height, this.Height), New Point (this. Width, this.Height)}; this.m_path.closefigure ();}

protected override void OnPaint (PaintEventArgs e) {base.OnPaint (e); ControlPaint.DrawSizeGrip (this.CreateGraphics (), System.Drawing.SystemColors.Control, this.Width-this.Height, 0, this.Height, this. HEIGHT);

}

protected override void OnSizeChanged (EventArgs e) {System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath (); path.StartFigure (); path.AddLines (new Point [] {new Point (this.Width , 0), New Point (this.width-this.height, this.height), New Point (this.width, this.Height); path.closefigure ();

Region retreg = new region; retreg.complement (m_path);

This.INValidate (REREG);

Base.onsizechanged (E); this.m_path = path;

ControlPaint.DrawSizeGrip (this.CreateGraphics (), System.Drawing.SystemColors.Control, this.Width-this.Height, 0, this.Height, this.Height);} protected override void WndProc (ref Message m) {if ( {base.WndProc (Ref m); Return;}

Switch (M.MSG) {Case WM_Nchittest: SendMessage (this.Parent.Handle, M.MSG, M.WParam, M.LParam); Base.WndProc (Ref M); if ((int) m.Result == HTClient ) {M.Result = (intptr) htbottomright; // Right} Break; Case WM_NCLButtondown: SendMessage (this.Parent.Handle, M.MSG, M.WPARAM, M.LPARAM; Break; Default: Base.WndProc REF M); Break;}}}}}

转载请注明原文地址:https://www.9cbs.com/read-82595.html

New Post(0)