【问题标题】:TabControl tab buttons locationTabControl 选项卡按钮位置
【发布时间】:2012-02-03 20:47:08
【问题描述】:

我正在为我的问题寻找解决方案。我想更改 tabcontrol 的 TabButtons 的位置或添加分配给 tabpage 但在 TabControl 之外的控件。 TabPages 是动态添加的。示例:

Form1___________ _ [] X

_______________________

Some TabPage content

Tab1 | Tab2 | Tab3 | < >

TextBox assigned to Tab's
________________________

因此,如果我通过单击Tab1Tab2Tab3 更改选项卡,TabPage + TextBox 内容应根据选项卡而更改。第一个想法是将 TabButtons 放在底部并添加包含 TextBox 内容的 ArrayList,捕获 TabControl 更改选项卡事件并更改 TextBox 内容,但编辑和添加该内容存在问题。简而言之:我不想将 TabButtons 放在 2 个控件之间(例如两个文本框之间)。您有什么想法吗?

【问题讨论】:

  • 很难说你想要什么。你能指出一个现有的做这种事情的网站吗?
  • 哦,我忘了说,这是windows应用程序
  • 下一个例子,neowin.net/images/uploaded/winlive-wm-convwin.png 但 TabButtons(user nicks) 应该在表情符号的位置。

标签: c# button tabcontrol


【解决方案1】:

如果我理解您的要求...当您单击一个选项卡时,您希望它控制两个不同的东西吗?像两个不同的文本框? 如果这是真的,你应该可以这样做。

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。

【讨论】:

【解决方案2】:

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

class MyOwnTextBox:TextBox
{
  public int parent_tab;
}

因此,您可以通过为它们分配 parent_tab id 来添加您的文本框。所以在标签按钮点击事件中,你可以做这样的事情:

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

【讨论】:

  • 有些东西对我来说很好,上面的帖子没有添加评论按钮!
  • 是的,我想控制一个位于 TabControl 控件之外的控件(TextBox),或者找到其他方式将 TabButtons 放在控件之间。
  • @user1182970 通过更多地参与本网站,您将获得发表评论的能力。
  • @jjnguy 我的浏览器没有显示添加按钮。对于上面的帖子/。
  • @user1182970 正确。您需要 50 声望才能将 cmets 留在这里。
【解决方案3】:

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

你可以像这样动态添加一个新的标签页

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

【讨论】:

    【解决方案4】:

    我不确定我是否完全理解您想要做什么。如果您想从另一个对象更改选项卡,只需使用:

     TabController.SelectTab(0);
    

    如果您想删除一个 TabPage 并将其添加到另一个,请使用:

     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.
     }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-01-31
      • 1970-01-01
      • 1970-01-01
      • 2011-03-28
      • 1970-01-01
      • 1970-01-01
      • 2021-08-04
      相关资源
      最近更新 更多