标签控制标签页隐藏 [英] Tab Control Tab Pages Hide

查看:93
本文介绍了标签控制标签页隐藏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个Windows窗体中有3个标签页(tb1,tb2,tb3)的tabcontrol(tab_control),我有另一个窗体(复选框控件),带有3个复选框(chk1,chk2,chk3)。我检查了chk1,chk2我希望输出标签页显示(tb1,tb2).how给出条件。当我加载表格时我想禁用访问tb3页面。



请帮助我!

解决方案

< blockquote>



TabControl一次只能显示一个TabPages。 TabControl可以显示/隐藏TabPage的文本,但一次不能显示多个TabPage。





TabControl包含一组TabPages。出于这个原因,我们使用添加和删除来显示和隐藏单个TabPages。





我是不确定为什么使用CheckBoxes来控制各个TabPages的显示。 TabControl识别TabPage标签上的单击并将该TabPage带到前面。我认为你使用CheckBoxes会造成一个不必要的复杂UI。





在设计师面前以下代码:





  • 宣布表格(Form1)
  • TabControl(tab_control)已添加到表单
  • 进入TabControl的TabPage集合中添加了TabPages

    (tb1,tb2,tb3)
  • 开每个TabPage,添加了一个合适的标签(tb1_LAB,tb2_LAB,

    tb3_LAB)
  • 三个CheckBox(chk1,chk2,chk3)被添加到表格


 使用系统; 
使用 System.Windows.Forms;

命名空间 TabPageExample
{

// ************************************* **************类Form1

public 部分 Form1:表格
{

/ / *********************************** ********* initialize_tb1

void initialize_tb1()
{
< span class =code-comment> // 初始化tb1内容
tb1_LAB.Text = @ 这是TabPage tb1;
}

// *********** ********************************* initialize_tb2

void initialize_tb2()
{
// initialize tb2内容
tb2_LAB.Text = @ 这是TabPage tb2;
}

// *********** ********************************* initialize_tb3

void initialize_tb3()
{
// initialize tb3内容
tb3_LAB.Text = @ 这是TabPage tb3;
}

// *********** ********************************* initialize_GUI

void initialize_GUI()
{
// hide所有TabPages
tab_control.TabPages.Remove(tb1);
tab_control.TabPages.Remove(tb2);
tab_control.TabPages.Remove(tb3);
// 设置检查状态
// 复选框
chk1.Checked = false ;
chk2.Checked = false ;
chk3.Checked = false ;
// 初始化TabPage内容
initialize_tb1();
initialize_tb2();
initialize_tb3();
// 显示除tb3以外的所有内容
chk1.Checked = ;
chk2.Checked = true ;
chk3.Checked = false ;
}

// *********** ****************************************** Form1

public Form1()
{
InitializeComponent();

initialize_GUI();
}

// *********** ***************************** chk_CheckedChanged

void chk_CheckedChanged( object sender,
EventArgs e)
{
CheckBox check_box =(CheckBox)sender;
bool is_checked = check_box.Checked;
string tag = check_box.Tag.ToString()。
ToLower()。
Trim();

switch (tag)
{
case chk1
if (is_checked)
{
tab_control.TabPages.Add(tb1);
}
else
{
tab_control.TabPages.Remove(tb1);
}
break ;

case chk2
if (is_checked)
{
tab_control.TabPages.Add(tb2);
}
else
{
tab_control.TabPages.Remove(tb2);
}
break ;

case chk3
if (is_checked)
{
tab_control.TabPages.Add(tb3);
}
else
{
tab_control.TabPages.Remove(tb3);
}
break ;

默认
throw new ApplicationException(
String .Format(
无法识别的CheckBox标记({0})
tag));
}
}

} // class Form1

} // 命名空间TabPageExample



此示例的项目文件可在 TabPageControl.zip中找到(11.4 KB) [ ^ ]。



希望有所帮助


I have tabcontrol (tab_control) with 3 tab pages (tb1,tb2,tb3)in the one Windows Form and i have another one form in (check box control)with 3 check box(chk1,chk2,chk3) .if i checked chk1,chk2 i want output tab pages show(tb1,tb2).how to i give the conditions. When I load the form I want to disable to access the tb3 pages.

please Help Me!

解决方案


A TabControl may only display one of its TabPages at a time. A TabControl can show/hide a TabPage's Text but it cannot show more than one TabPage at a time.



A TabControl contains a collection of TabPages. For that reason, we use Add and Remove to show and hide individual TabPages.



I'm not sure why you are using CheckBoxes to control the display of the individual TabPages. The TabControl recognizes a click on a TabPage tag and brings that TabPage to the front. I think that your use of CheckBoxes makes for an unnecessarily complex UI.



In the designer for the following code:



  • A Form (Form1) was declared
  • A TabControl (tab_control) was added to the Form
  • Into the TabControl's TabPage collection were added the TabPages
    (tb1, tb2, tb3)
  • On each TabPage, an appropriate Label was added (tb1_LAB, tb2_LAB,
    tb3_LAB)
  • Three CheckBoxes (chk1, chk2, chk3) were added to the Form

using System;
using System.Windows.Forms;

namespace TabPageExample
    {

    // *************************************************** class Form1

    public partial class Form1 : Form
        {

        // ******************************************** initialize_tb1

        void initialize_tb1 ( )
            {
                                        // initialize tb1 contents
            tb1_LAB.Text = @"This is TabPage tb1";
            }

        // ******************************************** initialize_tb2

        void initialize_tb2 ( )
            {
                                        // initialize tb2 contents
            tb2_LAB.Text = @"This is TabPage tb2";
            }

        // ******************************************** initialize_tb3

        void initialize_tb3 ( )
            {
                                        // initialize tb3 contents
            tb3_LAB.Text = @"This is TabPage tb3";
            }

        // ******************************************** initialize_GUI

        void initialize_GUI ( )
            {
                                        // hide all of the TabPages
            tab_control.TabPages.Remove ( tb1 );
            tab_control.TabPages.Remove ( tb2 );
            tab_control.TabPages.Remove ( tb3 );
                                        // set the Checked state of 
                                        // check boxes
            chk1.Checked = false;
            chk2.Checked = false;
            chk3.Checked = false;
                                        // initialize TabPage contents
            initialize_tb1 ( );
            initialize_tb2 ( );
            initialize_tb3 ( );
                                        // show all but tb3
            chk1.Checked = true;
            chk2.Checked = true;
            chk3.Checked = false;
            }

        // ***************************************************** Form1

        public Form1 ( )
            {
            InitializeComponent ( );

            initialize_GUI ( );
            }

        // **************************************** chk_CheckedChanged

        void chk_CheckedChanged ( object    sender, 
                                  EventArgs e )
            {
            CheckBox  check_box = ( CheckBox ) sender;
            bool      is_checked = check_box.Checked;
            string    tag = check_box.Tag.ToString ( ).
                                          ToLower ( ).
                                          Trim ( );

            switch ( tag )
                {
                case "chk1":
                    if ( is_checked )
                        {
                        tab_control.TabPages.Add ( tb1 );
                        }
                    else
                        {
                        tab_control.TabPages.Remove ( tb1 );
                        }
                    break;

                case "chk2":
                    if ( is_checked )
                        {
                        tab_control.TabPages.Add ( tb2 );
                        }
                    else
                        {
                        tab_control.TabPages.Remove ( tb2 );
                        }
                    break;

                case "chk3":
                    if ( is_checked )
                        {
                        tab_control.TabPages.Add ( tb3 );
                        }
                    else
                        {
                        tab_control.TabPages.Remove ( tb3 );
                        }
                    break;

                default:
                    throw new ApplicationException (
                        String.Format (
                            "Unrecognized CheckBox tag ({0})",
                            tag ) ); 
                }
            }

        } // class Form1

    } // namespace TabPageExample


The project files for this example may be found at TabPageControl.zip (11.4 KB)[^].


Hope that helps


这篇关于标签控制标签页隐藏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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