本文介绍了如何避免添加Tabsages我一次又一次点击按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个按钮,每个按钮都会显示一个带有用户控件的标签页...
一切正常...但是当我点击一个按钮标签页面正在显示,如果我再次按下该按钮,则显示另一个标签页...就像明智的那么多,...我们点击按钮多少次...多次显示标签页面....
i希望控制许多标签页的出现.....我想显示当我点击按钮时已经显示的相同标签...
the我写的代码是
i have two buttons, each of them will display a tab page with an user control...
all are working ok.. but when i click a button the tab page is displaying and if i press that button again another tab page is displaying... like wise so many,.. how many times we click the button... that many times the tab pages are displaying....
i want to control the occurrence of many tab pages..... i want to display the same tab that already displayed when ever i click the button ...
the code i written 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
{
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");
page.Controls.Add(contentControl);
//tabControl1.TabPages.Clear();
tabControl1.TabPages.Add(page);
tabControl1.SelectedTab = page;
button1.Visible = true;
button2.Visible = true;
}
private void button2_Click(object sender, EventArgs e)
{
tabControl1.Visible = true;
var contentControl = new hhh();
contentControl.Dock = DockStyle.Fill;
var page = new TabPage("Education");
page.Controls.Add(contentControl);
tabControl1.SelectedTab = page;
//tabControl1.TabPages.Clear();
tabControl1.TabPages.Add(page);
button1.Visible = true;
button2.Visible = true;
}
}
}
推荐答案
//Declare at class level.
TabPage languagesPage = null;
TabPage educationPage = null;
//Put this check before initializing the object. Do the same for other tab too.
if(educationPage == null)
{
educationPage = new TabPage("Education");
page.Controls.Add(contentControl);
tabControl1.TabPages.Add(page);
}
tabControl1.SelectedTab = educationPage ;
这篇关于如何避免添加Tabsages我一次又一次点击按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!