如何防止用户添加对特定位置的控制? [英] How to prevent user to add control on specific location?
问题描述
之前我发布了一个关于 是主要的用户控件将放在表格上.
-
还要注意 RECT
结构是一个 ltrb
矩形而不是 xywh
矩形.
不正确
您不应显式设置值:
ncRect.top = 68;//<----ncRect.left = 176;//<----ncRect.bottom -= 68;ncParams.rectProposed.top = 68;//<----ncParams.rectProposed.left = 176;//<----ncParams.rectProposed.bottom -= 68;
正确
而是向/从矩形添加 (+=
) 或减去 (-=
):
ncRect.top += 30;//<---- 30px 上边距ncRect.left += 50;//<---- 50px 左边距ncRect.bottom -= 20;//<---- 20px 下边距ncParams.rectProposed.top += 30;ncParams.rectProposed.left += 50;ncParams.rectProposed.bottom -= 20;
注意
如果您没有正确绘制非客户区,并且将控件放置在比方说 -5, -5
的位置,那么该控件可能看起来好像它在里面 非客户区.
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
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.
这篇关于如何防止用户添加对特定位置的控制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!