如何在页面控制中允许或禁止用户输入选项卡?
我想限制用户(基于特殊条件)在页面控件中打开或不打开选项卡。即,用户可以单击该选项卡,但不会向他显示该选项卡。相反,一条消息将向他显示“他没有查看此类选项卡的访问权限
”。
在什么情况下我应该编写检查代码,以及什么选项卡属性(TPageControl
组件)将允许/阻止用户进入此类选项卡?
I want to restrict users (based on special condition) to open a tab or not in a page control. ie, the user can click on the tab but it will not be displayed to him. Instead, a message will show to him that "he don't have the access right to see such tab
".
On what event I should write the checking code, and what tab property (of TPageControl
component) will allow/block user to enter such tab?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
在理想情况下,您可以从
OnChanging
事件将AllowChange
设置为False
以阻止页面更改。然而,这似乎并不可行,因为我无法从OnChanging
中辨别用户试图选择哪个页面。即使查看底层的 Windows 通知似乎也没有什么希望。据我所知,
TCN_SELCHANGING
通知标识了该控件,但并未说明所涉及的页面。我能想到的最好办法是使用
OnChanging
来记录当前活动页面,然后在OnChange
中完成艰苦的工作。如果所选页面已更改为不需要的内容,则只需将其更改回来即可。我知道相当混乱,但它有工作的优点!
In an ideal world you would set
AllowChange
toFalse
from theOnChanging
event to block a page change. However, this does not appear to be viable because I can find no way of discerning, from withinOnChanging
, which page the user is trying to select.Even looking at the underlying Windows notification seems to offer little hope. The
TCN_SELCHANGING
notification identifies the control, but not says nothing about the pages involved, so far as I can tell.The best I can come up with is to use
OnChanging
to note the current active page and then do the hard work inOnChange
. If the selected page has been changed to something undesirable, then just change it back.Rather messy I know, but it has the virtue of working!
OnChanging
事件不允许您确定正在选择哪个选项卡,因为 Windows 本身不报告该信息。但是,您可以做的是,子类化TPageControl.WindowProc
属性,以在处理发送到TPageControl
之前拦截消息。使用鼠标消息来确定哪个选项卡被直接单击(查看TPageControl.IndexOfTabAt()
方法),并使用键盘消息来检测左/右箭头按下以确定哪个选项卡与该选项卡相邻。活动选项卡(查看TPageControl.FindNextPage()
方法)。The
OnChanging
event does not allow you to determine which tab is being selected, because Windows itself does not report that information. What you can do, however, is subclass theTPageControl.WindowProc
property to intercept messages that are sent to theTPageControl
before it processes them. Use mouse messages to determine which tab is being clicked on directly (look at theTPageControl.IndexOfTabAt()
method), and use keyboard messages to detect left/right arrow presses to determine which tab is adjacent to the active tab (look at theTPageControl.FindNextPage()
method).使用页面控件的
OnChanging
事件。好的,PageControle1.TabIndex 是活动页面索引,而不是我想要选择的页面索引。
我怎样才能获得点击的页面。
新尝试
Use the
OnChanging
event of the page control.Ok, the PageControle1.TabIndex is the activepageindex and not the one i want to select.
How can i get the clicked Page.
New Attempt
有时,最好用这样的东西隐藏不需要的选项卡:
比试图阻止切换到这些选项卡更好。
当然,如果 OnChanging 事件中的 Sender 是 TabSheet 而不是 TPageControl 会更好。
Sometimes it is better just to hide unwanted TabSheets with something like this:
than trying to prevent switching to these tabs.
Sure, it would be better if Sender in OnChanging event will be TabSheet , not TPageControl.
您可以在 TPageControl 的 OnChanging 事件中显示选项卡并有效禁用更改。您需要做的就是将AllowChange var 设置为False。
You can show tab and effectively disable changing in OnChanging event of TPageControl. All you need to do is set AllowChange var to False.