C++/CLI Form Resize Problem After Fill Panel

Wami007 296 Reputation points
2021-04-20T13:47:21.883+00:00

I want resize my Panel Filled Form with BOTTOMLEFT, BOTTOM in addition to BOTTOMRIGHT

My Default Resizing Code Resize only Form without Panel :

          const int cGrip = 16;
          const int cCaption = 32;
      void WndProc(Message% m) override
       {
           switch (m.Msg)
           {
           case WM_NCHITTEST:
               Point pos = Point(m.LParam.ToInt32());
               pos = PointToClient(pos);
               if (pos.Y < cCaption)
               {
                   m.Result = IntPtr(HTCAPTION);
                   return;
               }
               if (pos.X >= ClientSize.Width - cGrip && pos.Y >= ClientSize.Height - cGrip)
               {
                   m.Result = IntPtr(HTBOTTOMRIGHT);
                   return;
               }
               break;
           }
           __super::WndProc(m);
       }
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,301 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,542 questions
.NET Runtime
.NET Runtime
.NET: Microsoft Technologies based on the .NET software framework.Runtime: An environment required to run apps that aren't compiled to machine language.
1,125 questions
{count} votes

3 answers

Sort by: Most helpful
  1. Viorel 112.5K Reputation points
    2021-04-21T07:45:58.217+00:00

    To resize the child control automatically after resizing the form, set its Anchor properties. This can be done in Form Designer manually, or programmatically:

    panel1->Anchor = (AnchorStyles)(AnchorStyles::Left | AnchorStyles::Top | AnchorStyles::Right | AnchorStyles::Bottom);
    

    Show more details if you need a special behaviour.


  2. Jeanine Zhang-MSFT 9,181 Reputation points Microsoft Vendor
    2021-04-21T08:02:10.19+00:00

    According to the Doc:

    If the mouse is not captured, the message is sent to the window beneath the cursor. Otherwise, the message is sent to the window that has captured the mouse.

    As far as I'm concerned, When the DOCK attribute of the panel is Fill, the message is sent to the panel window instead of the form window. So we couldn't resize the form after fill panel.

    I suggest you could try to override OnSizeChanged of form and set the region of panel same size as form and then exclude its bottom right corner. This way, the excluded region doesn't belong to panel anymore and all messages including WM_NCHITTEST will be received by our WndProc; the panel even doesn't draw that region.

    Here is my code:

    protected:  
    	void OnSizeChanged(EventArgs ^ e) override  
    	{			  
    		region = gcnew System::Drawing::Region(System::Drawing::RectangleF(0, 0, this->Width, this->Height));  
    		sizeGripRectangle = gcnew System::Drawing::RectangleF (this->Width - tolerance, this->Height - tolerance, tolerance, tolerance);  
    		region->Exclude(*sizeGripRectangle);  
    		this->panel1->Region = region;  
    		this->Invalidate();  
    
    	}  
    

    Best Regards,

    Jeanine


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


  3. Artemiy Moroz 271 Reputation points
    2021-04-24T16:10:39.48+00:00

    hi there!

    I would suggest you catch WM_MOUSEMOVE messages. WM_NCHITTEST if for different purposes