![]() The Panel itself hosts a PictureBox that displays an image and a Label to display the title. To subclass, pass a Control to a derived class from NativeWindow, assign its handle and override the WndProc method to trap the WM_NCHITTEST messages and assign the HTTRANSPARENT pointer to the Result property.Īn example here for a borderless Form that contains a Panel docked to the top. a PictureBox that shows the Icon and a Label that displays the caption/title.). Do the same for the panel's non-click child controls if any (i.e. Well, you don't need to do that, a simple alternative is to subclass the panel's native window to make it transparent to the mouse inputs and relay them to the parent to process. As a result, the Form's move and resize routines do not work in the panel's region which makes you replicate almost the same code to handle the panel's mouse inputs separately. The title-bar Panel is the problem here which receives the mouse inputs and not the From. Private void Form1_MouseMove(object sender, MouseEventArgs e)ĬursorType = 32() ĬursorType = 32() ĬursorType = 32() ĬursorType = 32() Ĭursor.Current = new Cursor(new IntPtr(cursorType)) ResizeDir = ResizeDirection(e.Location, this.Bounds) If (e.Button = MouseButtons.Left & !isDragging) Private void Form1_MouseDown(object sender, MouseEventArgs e) ![]() Private void Form1_MouseUp(object sender, MouseEventArgs e) ![]() Private void titleBarPanel_MouseUp(object sender, MouseEventArgs e) This.Height = Math.Max(, e.Y - + this.Height) This.Width = Math.Max(, e.X - + this.Width) This.Left = Math.Min(this.Left + e.X -, this.Left + this.Width - ) This.Width = Math.Max(, - e.X + this.Width) This.Height = Math.Max(, - e.Y + this.Height) Private void titleBarPanel_MouseMove(object sender, MouseEventArgs e) Private void titleBarPanel_MouseDown(object sender, MouseEventArgs e) Private int ResizeDirection(Point cursorPos, Rectangle formBounds)Įlse if (cursorPos.Y > formBounds.Bottom - 10)Įlse if (cursorPos.X formBounds.Right - 10) Point pos = new Point(m.LParam.ToInt32() & 0xffff, m.LParam.ToInt32() > 16) Įlse if (pos.Y > - 10)Įlse if (pos.X - 10) Protected override void WndProc(ref Message m) This.MouseUp += new MouseEventHandler(Form1_MouseUp) This.MouseMove += new MouseEventHandler(Form1_MouseMove) This.MouseDown += new MouseEventHandler(Form1_MouseDown) TitleBarPanel.MouseUp += new MouseEventHandler(titleBarPanel_MouseUp) TitleBarPanel.MouseMove += new MouseEventHandler(titleBarPanel_MouseMove) TitleBarPanel.MouseDown += new MouseEventHandler(titleBarPanel_MouseDown) I also tried asking ChatGPT but well he was not that smart in that case and couldn't resolve my problem.ĭue to small volume of the code I will give the entire code. I have searched through stackoverflow asd well as on youtube but I couldn't find anything. I want to simply enable the form to be resizable by the top panel object. I have already enabled the resizing of the form by the Bottom and Sides of the form and enabled dragging of the form by the titleBarPanel. So I created the project, set Border property of the main form to None and added the Panel object which I called titleBarPanel. (Please keep in mind that I am C# newbie) ![]() I want to make a simple C# (VS) pop-up window for my project in python, I want to use VS due to aesthetics.
0 Comments
Leave a Reply. |