Adjust the form without a border with a mouse

xiaoxiao2021-03-06  73

The code here is a size or position used to simulate the adjustment of a window (preferably no side form), interesting, feel easy to play, bring to you, hope that the high people will point to Improved procedures (modified), use this method to do Window form control, so you can adjust your control size or location at runtime, pay attention to use WNDPROC:

Using system.drawing; using system.windows.forms;

A summary description of Namespace Size_MoveForm {///

/// FORMBASE. /// You can adjust the size of the form and the location of the mobile form, if you need to inherit a new form or form instance / /// from this ////mmary> Public class form is: system.windows.Forms.form {/// // The required designer variable. /// private system.componentmodel.container components = null;

Public formbase () {// // Windows Form Designer Support for // InitializeComponent ();

// // Todo: Add any constructor code after INITIALIZEComponent call //}

///

/// Clean all the resources being used. /// Protected Override Void Dispose (Bool Disposing) {if (disponents! = Null) {components.dispose ();}} Base.Dispose

#REGION Windows Form Designer The code ///

/// designer supports the required method - do not use the code editor to modify the // / this method. /// private () {///FormBaseSize = new system.drawing.size (6, 14); this.clientsize = new system.drawing.size (192, 146 ); This.formborderstyle = system.windows.forms.formorderstyle.none; this.name = "formbase"; this.text = "formbase";

} #Endregion

Private const INT WM_NCHITTEST = 0x84; // Move the mouse, press and hold or release the system message occurred when the mouse occurs private const INT HTCLIENT = 0x1; // Workspace private const port htsysmenu = 3; // System menu private const Int htcaption = 0x2 ; //title

Private const Int htleft = 10; // To left private const Int htright = 11; // To right private const Int httop = 12; // to the top left private const Int httopright = 14; // upper right private const int HTBOTTOM = 15; // private downwardly const int HTBOTTOMLEFT = 16; // the left private const int HTBOTTOMRIGHT = 17; // the right private int m_BorderWidth = 2; private int m_CaptionHeight = 20; Private const Int borderwidth = 5; // ourselves defined the width of the form side

/ / Can adjust the size of the form and the position of the mobile form protected override void wndproc (REF Message M) {if (M.MSG == WM_NCHITTEST) {base.WndProc (Ref m); if (designMode) {return;} IF ((int) m.Result == htclient) {m.hwnd = this.handle;

System.drawing.Rectangle Rect = this.Rectangletoscreen (this.clientRectangle); Point C_POS = Cursor.position;

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

New Post(0)