How to prevent user to add control on specific location?

北慕城南 提交于 2019-12-24 12:13:27

问题


Previously I have posted a question about How to create non-client area? and I got my answer. Now, I want to prevent user to add control on specific client area.So, User can add control only on allocated portion of client area.

The control should be looked like this.

CLASS DESIGN & CODES

XWizardControl: is the main user control which will be placed on form.

XWizardPageWindow: is the container which will contains all XWizardPages. This control will be placed on the XWizardControl. User will add pages from the Control Collection Dialog Window.

XWizardPageCollection: is the collection of XWizardPage.

XWizardPage: user will place other controls here.

XWizardPageDesigner: Control designer for XWizardPage control


回答1:


You're setting the nonclient rectangle incorrectly.

"On entry, the structure contains the proposed window rectangle for the window. On exit, the structure should contain the screen coordinates of the corresponding window client area." -MSDN-

Also notice that the RECT structure is a ltrb rectangle and not a xywh rectangle.

Incorrect

You shouldn't set the values explicit:

ncRect.top = 68; //<----
ncRect.left = 176; //<----
ncRect.bottom -= 68;

ncParams.rectProposed.top = 68; //<----
ncParams.rectProposed.left = 176; //<----
ncParams.rectProposed.bottom -= 68;

Correct

But rather add (+=) or subtract (-=) to/from the rectangle:

ncRect.top += 30; //<---- 30px top-margin
ncRect.left += 50; //<---- 50px left-margin
ncRect.bottom -= 20; //<---- 20px bottom-margin

ncParams.rectProposed.top += 30;
ncParams.rectProposed.left += 50;
ncParams.rectProposed.bottom -= 20;

Note

If you don't paint the nonclient area correctly, and a control is placed at lets say the location -5, -5, then the control may appear as if it's inside the nonclient area.



来源:https://stackoverflow.com/questions/22296466/how-to-prevent-user-to-add-control-on-specific-location

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!