选项卡控件标签页禁用 [英] tab control tab pages disable
问题描述
亲爱的开发人员,
我在Windows窗体中有tabcontrol(tab_control)和3个标签页(tb1,tb2,tb3)。当我加载表单时,我想禁用访问tb3页面。用户可以看到该页面,但用户无法访问tb3页面。像textbox.Enable = false;
我尝试下面的代码,但它不工作
< pre lang =c#>表格加载
{
tab_control.SelectedIndex [ 2 ]。启用= 假跨度>;
}
问候
Vasanthakumar 在TabControl中添加
选择
事件:
private void tab_control_Selecting( object sender,TabControlCancelEventArgs e)
{
if (e.TabPage == tb3)
{
e.Cancel = 真跨度>;
}
}
如果用户选择tb3,则此代码取消选择。
据我所知,标签页没有Enabled属性。在你使用的代码中,SelectedIndex
只设置或获取选项卡控件选择的索引,它不会改变页面的属性。
你可以通过禁用该页面中的控件或取消选择事件来实现类似的效果。
这是禁用页面内容的简单方法之一
((控制)此 .tb3).Enabled = false ;
或者,如果用户选择tb3,您可以取消选择事件。
private void tabControl1_Selecting( object sender,TabControlCancelEventArgs e)
{
if ( this .tabControl1.SelectedTab.Name == tb3 )
{
e.Cancel = true ;
}
}
这样,用户甚至无法查看页面内容,他们只知道那里有存在tb3。请注意,事件handeler是tabControl1_Selecting
而不是tabControl1_SelectedIndexChanged
。在你的情况下,我认为第二个选项更符合你的要求。
希望这是有帮助的。
如果你有兴趣可以通过创建自己的TabControl来隐藏它们:
public class MyTabControl:TabControl
{
protected 覆盖 void WndProc( ref 消息m)
{
// 通过捕获TCM_ADJUSTRECT消息来隐藏标签
如果(m。 Msg == 0x1328&&!DesignMode)
m.Result = IntPtr .Zero;
else
base .WndProc(参考 m);
}
}
您可以在TabPages by SelectedIndex ++或SelectedIndex -
Dear Developers,
I have tabcontrol (tab_control) with 3 tab pages (tb1,tb2,tb3)in the Windows Form. When I load the form I want to disable to access the tb3 pages. User can see that page, but user couldn't be able to access the tb3 page. Like textbox.Enable=false;
I try that below code but it is not working
Form Load
{
tab_control.SelectedIndex[2].Enable = false;
}
Regards
Vasanthakumar
Add aSelecting
event to your TabControl:
private void tab_control_Selecting(object sender, TabControlCancelEventArgs e) { if (e.TabPage == tb3) { e.Cancel = true; } }
If the user selects tb3, this code cancels the selecting.
Hi,
As far as I know, a tab page doesn't have an Enabled property. In the code you use,SelectedIndex
only set or get the tab controls selected index, it does not change the property of the page.
You can achieve similar effect by disabling the controls in that page or cancel the selection event.
This is one of the easy way of disabling the contents in the page
((Control)this.tb3).Enabled = false;
Or you can cancel the selection event if user select tb3.
private void tabControl1_Selecting(object sender, TabControlCancelEventArgs e) { if (this.tabControl1.SelectedTab.Name == "tb3") { e.Cancel = true; } }
This way, user cannot even view the content of the page, they just know there's a tb3 exists. Note that the event handeler istabControl1_Selecting
nottabControl1_SelectedIndexChanged
. In your case I think the second option fits your requirement more.
Hope this is helpful.
If you are interested you can hide them by creating your own TabControl:
public class MyTabControl : TabControl { protected override void WndProc(ref Message m) { // Hide tabs by trapping the TCM_ADJUSTRECT message if (m.Msg == 0x1328 && !DesignMode) m.Result = IntPtr.Zero; else base.WndProc(ref m); } }
You can navigate between TabPages by SelectedIndex++ or SelectedIndex--
这篇关于选项卡控件标签页禁用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!