禁用选项卡控件的选项卡 [英] disable tabpages of tab control

查看:99
本文介绍了禁用选项卡控件的选项卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



如何禁用和启用tabcontrol的tabpage?

例如,我有两个按钮名称为Start和Stop以及2个tabpages。当我按下开始时,第1页的表格被禁用,只能访问第2页的表格!(这意味着我可以按名称查看2个标签页,但无法访问标签页1号!并且表示不删除或隐藏标签页1号!!)。当我按下Stop时,tabpage no.2被禁用,只能访问第1页标签!

如果我们禁用它,我怎么能禁用(不隐藏和删除)tabpage作为文本框?

解决方案

如果您正在谈论WinForms选项卡控件,则无法删除标签页。



您可以尝试通过拦截 SelectedIndexChanged 标签控件事件来模拟所需的行为。

如果选中的标签页为已禁用,则可以将SeletedTab重新分配给启用的。





这样的东西:



  private   void  tabControl1_SelectedIndexChanged( object  sender,EventArgs e)
{
if (tabControl1.SelectedTab == tabPage3)
tabControl1.SelectedTab = tabPage1;
}


可以使用您要禁用的标签的ID禁用标签页 -



tabItinerary.Enabled = false


如果您正在谈论WinForms,唯一的方法是遍历该标签页上的所有控件并禁用它们一个人。例如:



  private   void  DisableTabPage(TabPage tbPg)
{
foreach (控制c in tbPg.Controls)
c.Enabled = false ;
}

private void EnableTabPage(TabPage tbPg)
{
foreach (控制c tbPg.Controls)
c。已启用= true ;
}





您可以在代码中用以下代码来打电话:



  //  禁用 
DisableTabPage(tabPage1 );

// 或者启用
EnableTabPage(tabPage1);





TabPage确实有 .Enabled 属性,但它没有做任何事情(我不认为它出现在Intellisense中,它也有一个 .Visible 属性,它不显示或做任何事情)。遗憾的是,在WinForms中他们无法做到这一点。



但是,如果你在谈论WPF,那么你可以使用<$ c来禁用它们$ c> .IsEnabled 或 .IsVisible 属性,但由于你使用的是TabPage而不是TabItem,我猜你正在使用WinForms。


hi
how can i disable and enable a tabpage of tabcontrol?
for ex., i have 2 buttons by name as Start and Stop and 2 tabpages. when i press on Start, tabpage no.1 is disabled and just can access to tabpage no.2!(it means i can see 2 tabpages by their names, but can't access to tabpage no.1! and means not to remove or hide tabpage no.1!!). when i press on Stop, tabpage no.2 is disabled and just can access to tabpage no.1!
how can i disable(not hide and remove) tabpage as a textbox, when we disable it?

解决方案

If you are talking about WinForms tab control, you cannot disble tab page.

You can try to simulate behavior you need by intercepting SelectedIndexChanged event of tab control.
If selected tab page is "disabled" one, you can reassign SeletedTab to the "enabled" one.


Something like this:

private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
{
    if (tabControl1.SelectedTab == tabPage3)
        tabControl1.SelectedTab = tabPage1;
}


Tab page can be disabled by using the ID of the Tab you want to disabled -

tabItinerary.Enabled=false


If you are talking about WinForms, the only way to do it is to loop through all the controls on that tab page and disable them one by one. For example:

private void DisableTabPage(TabPage tbPg)
{
    foreach (Control c in tbPg.Controls)
        c.Enabled = false;
}

private void EnableTabPage(TabPage tbPg)
{
    foreach (Control c in tbPg.Controls)
        c.Enabled = true;
}



You would then call it in code with:

//To disable
DisableTabPage(tabPage1);

//Or to enable
EnableTabPage(tabPage1);



TabPage does have an .Enabled property but it doesn't do anything (I don't think it shows up in Intellisense, it also has a .Visible property that doesn't show up or do anything). Shame that in WinForms they don't have a way to do it.

However, if you are talking about WPF, then you can disable them using the .IsEnabled or .IsVisible property, but since you used the word TabPage instead of TabItem I'm guessing you are using WinForms.


这篇关于禁用选项卡控件的选项卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆