如何根据按钮单击显示tabpages而不是tab index? [英] how to display tabpages according to button click instead of tab index?

查看:72
本文介绍了如何根据按钮单击显示tabpages而不是tab index?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



i有三个按钮和三个标签页。

每个按钮显示每个标签页。



喜欢but1,but2,但是。

但是1显示tab1,但是diaplays tab2和but3显示tab3。



如果but1 diaplays tab1和but2显示tab2而but3通过从but1,but2和but3按顺序显示tab3。它们按顺序显示。再次如果我按下but2它显示(来自)已经显示的tab2。像其他2个按钮一样...







当首先点击but2时,tab2正在显示,但是单击了tab1显示,但是3点击了tab3显示..这里的订单是tab2> tab1> tab3。



根据规则,如果but1现在已经被cliked ,tab2应该显示,但是2显示tab2和but3显示tab3 ....但是这里发生的是......如果订单是tab2> tab3> tab1。并且按下了but1,tab2正在前面,但是按下了2,tab3正在前面,而but3被按下tab1正在前面...我写的代码是...

使用系统; 
使用System.Collections.Generic;使用System.ComponentModel
;
使用System.Data;使用System.Drawing
;
使用System.Linq;
使用System.Text;
使用System.Windows.Forms;

namespace Ttr
{
public partial class Form1:Form
{
TabPage languages = null;
TabPage education = null;
TabPage job = null;
public Form1()
{
InitializeComponent();
tabControl1.Visible = false;

}

private void button1_Click(object sender,EventArgs e)
{
tabControl1.Visible = true;
var contentControl = new tta();
contentControl.Dock = DockStyle.Fill;
var page = new TabPage(Languages);
if(languages == null)
{
languages = new TabPage(Languages);
page.Controls.Add(contentControl);

//tabControl1.TabPages.Clear();
tabControl1.TabPages.Add(page);
tabControl1.SelectedTab = page;
}

其他
{
tabControl1.SelectedTab = languages;
tabControl1.SelectedIndex = 0;
}
}

private void button2_Click(object sender,EventArgs e)
{
tabControl1.Visible = true;
var contentControl = new hhh();
contentControl.Dock = DockStyle.Fill;
var page = new TabPage(Education);
if(education == null)
{
education = new TabPage(Education);
page.Controls.Add(contentControl);
tabControl1.SelectedTab = page;
//tabControl1.TabPages.Clear();
tabControl1.TabPages.Add(page);
}
其他
{
tabControl1.SelectedTab = education;
tabControl1.SelectedIndex = 1;

}
}

private void button3_Click(object sender,EventArgs e)
{

tabControl1.Visible = true ;
var contentcontrol = new job();
contentcontrol.Dock = DockStyle.Fill;
var page = new TabPage(职位名称);
if(job == null)
{
job = new TabPage(Job Titles);
page.Controls.Add(contentcontrol);
tabControl1.SelectedTab = page;
tabControl1.TabPages.Add(page);
}
其他
{
tabControl1.SelectedTab = job;
tabControl1.SelectedIndex = 2;

}
}
}
}



请按照按钮帮助显示标签页,但是不是通过索引....

解决方案

我会改写这样的方法:



< pre lang =cs> private void button1_Click( object sender,EventArgs e)
{
if (languages == null
{
tabControl1.Visible = true ;
var contentControl = new tta();
contentControl.Dock = DockStyle.Fill;
languages = new TabPage( Languages );
languages.Controls.Add(contentControl);

tabControl1.TabPages.Add(语言);
tabControl1.SelectedTab = languages;
}
else
{
tabControl1.SelectedTab = languages;
}
}


hi guys,

i have three buttons and three tabpages.
each button displays each tabpage.

like but1, but2, but3.
but1 displays tab1, but diaplays tab2 and but3 displays tab3.

if but1 diaplays tab1 and but2 displays tab2 and but3 displays tab3 by clicking in order from but1,but2 and but3. they are displaying in order. and again if i press but2 it displays(comes to from) tab2 that already displayed. like other 2 buttons does the same...

but

when but2 is clicked first, tab2 is displaying and but1 clicked tab1 displaying and but3 clicks tab3 displayes.. here the order is tab2>tab1>tab3.

as per the rule, if but1 is cliked now, tab1 should be displayed, but2 display tab2 and but3 displays tab3.... but here what is happening is...... if the order is tab2>tab3>tab1. and but1 is pressed tab2 is coming front, but2 is pressed, tab3 is coming front, and but3 is pressed tab1 is coming front... the code i written to do so is..

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ttr
{
    public partial class Form1 : Form
    {
        TabPage languages = null;
        TabPage education = null;
        TabPage job = null;
        public Form1()
        {
            InitializeComponent();
            tabControl1.Visible = false;

        }

        private void button1_Click(object sender, EventArgs e)
        {
            tabControl1.Visible = true;
            var contentControl = new tta();
            contentControl.Dock = DockStyle.Fill;
            var page = new TabPage("Languages");
            if (languages == null)
            {
                languages = new TabPage("Languages");
                page.Controls.Add(contentControl);

                //tabControl1.TabPages.Clear();
                tabControl1.TabPages.Add(page);
                tabControl1.SelectedTab = page;
            }

            else
            {
                tabControl1.SelectedTab = languages;
                tabControl1.SelectedIndex = 0;
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            tabControl1.Visible = true;
            var contentControl = new hhh();    
            contentControl.Dock = DockStyle.Fill;
            var page = new TabPage("Education");
            if (education == null)
            {
                education = new TabPage("Education");
                page.Controls.Add(contentControl);
                tabControl1.SelectedTab = page;
                //tabControl1.TabPages.Clear();
                tabControl1.TabPages.Add(page);
            }
            else 
            {
                tabControl1.SelectedTab = education;
                tabControl1.SelectedIndex = 1;
                
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
           
            tabControl1.Visible = true;
            var contentcontrol = new job();
            contentcontrol.Dock = DockStyle.Fill;
            var page = new TabPage("Job Titles");
            if (job == null)
            {
                job = new TabPage("Job Titles");
                page.Controls.Add(contentcontrol);
                tabControl1.SelectedTab = page;
                tabControl1.TabPages.Add(page);
            }
            else
            {
                tabControl1.SelectedTab = job;
                tabControl1.SelectedIndex = 2;
                
            }
        }
    }
}


please help to display tab pages according to button, but not through the index....

解决方案

I would rewrite the methods like this:

private void button1_Click(object sender, EventArgs e)
{
    if (languages == null)
    {
        tabControl1.Visible = true;
        var contentControl = new tta();
        contentControl.Dock = DockStyle.Fill;
        languages = new TabPage("Languages");
        languages.Controls.Add(contentControl);

        tabControl1.TabPages.Add(languages);
        tabControl1.SelectedTab = languages;
    }
    else
    {
        tabControl1.SelectedTab = languages;
    }
}


这篇关于如何根据按钮单击显示tabpages而不是tab index?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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