C# 选项卡控制选项卡按钮位置

C# 选项卡控制选项卡按钮位置,c#,button,tabcontrol,C#,Button,Tabcontrol,我正在寻找解决我问题的办法。我想更改tabcontrol的TabButtons的位置,或者添加分配给tabpage但在tabcontrol之外的控件。选项卡页是动态添加的。例如: Form1___________ _ [] X _______________________ Some TabPage content Tab1 | Tab2 | Tab3 | < > TextBox assigned to Tab's ________________________ Form

我正在寻找解决我问题的办法。我想更改tabcontrol的TabButtons的位置,或者添加分配给tabpage但在tabcontrol之外的控件。选项卡页是动态添加的。例如:

Form1___________ _ [] X

_______________________

Some TabPage content

Tab1 | Tab2 | Tab3 | < >

TextBox assigned to Tab's
________________________
Form1\uuuuuuuuuuuuuuuuuuuuuuuux[]
_______________________
一些选项卡页内容
表1 |表2 |表3 |<>
分配给选项卡的文本框
________________________

因此,如果我通过单击
Tab1
Tab2
Tab3
TabPage+TextBox来更改选项卡,则内容应根据选项卡的不同而变化。第一个想法是将TabButtons放在底部,并添加ArrayList,其中包含TextBox内容、catch TabControl change tab事件和change TextBox内容,但编辑和添加该内容时存在问题。简而言之:我不想在两个控件之间(例如在两个文本框之间)放置TabButtons。您有什么想法吗?

您可以创建自己的文本框类,该类继承自文本框类:

class MyOwnTextBox:TextBox
{
  public int parent_tab;
}
因此,您可以通过为文本框指定父选项卡id来添加文本框。因此,在tab button click事件中,您可以执行以下操作:

foreach(MyOwnTextBox txt in this.Controls)
{
   if(txt.parent_tab==1) txt.visible=false;
}

我不太清楚你到底想干什么。如果要更改其他对象的选项卡,只需使用:

 TabController.SelectTab(0);
如果要删除选项卡页并将其添加到另一个选项卡页,请使用:

 TabController.Controls.Remove(TabPage1);
 TabController2.Controls.Add(TabPage1);
编辑:进一步阅读后,我认为您需要以下内容:

 this.TabController.ControlAdded += AddLinksToBottomOfTabs;
 public void mainSettingsTabController_ControlAdded(object sender, ControlEventArgs e)
 {
     //Create label with e.Control.Name as the title and 
     //add it to wherever you want it added.
 }

也可以将选项卡放置在选项卡控件的左侧或右侧。这并不完美,但比将它们放在选项卡控件的上方或下方更接近您的想法

您可以像这样动态添加一个新的选项卡页面

tabControl1.TabPages.Add("My new Tab");

如果我明白你的要求。。。你想当你点击一个标签时,它控制两个不同的东西吗?像两个不同的文本框? 如果这是真的,你应该可以这样做

foreach (thing in your ArrayList)
{
     TabPage tabPage = new TabPage("Name of tab");            // Add a new tab page
     RichTextBox rtb = new System.Windows.Forms.RichTextBox();//RTF box
     TextBox tb = new System.Windows.Forms.TextBox();         //Text box

     //Set up size, position and properties
     rtb.LoadFile("some/Path/to/a/file");

     //set up size, position of properties
     tb.Text = "Some text I want to display";

     tabPage.Controls.Add(rtb); //Add both boxes to that tab
     tabPage.Controls.Add(tb);

     tabControl1.TabPages.Add(tabPage); //Add that page to the tab control
}

你唯一需要搞乱的就是布局。并确保在设计器中添加tabControl。

很难说出您想要什么。你能指出一个现有的网站做这样的事情吗?哦,我忘了提到,这是windows应用程序下一个例子,但TabButtons(用户刻痕)应该在表情符号的地方。有些东西对我很好,上面的帖子中没有为我添加评论的按钮!是的,我想控制TabControl控件之外的一个控件(文本框),或者找到其他方法在控件之间放置TabButtons。@用户1182970如果更多地参与此网站,您将获得评论功能。@jjnguy我的浏览器不显示“添加”按钮。以上帖子/@user1182970正确无误。你需要50个声誉才能在这里留下评论。几乎所有我的意思,但标签更改按钮应该在这些文本框之间。你应该能够用属性更改位置。这可能会有帮助