-1
有没有办法冻结C#.net标签页控件的第一个标签页?冻结C#.net标签控件中的第一个标签页
我有一个可以有许多选项卡的选项卡控制器。如果用户正在滚动它们,第一个标签应该保持在第一个位置,剩下的标签应该移动。
我试图使用删除并在paint方法中插入选项卡。但似乎是我试图删除并添加第一页时,有时会获得索引问题。
// For the first time home tab comes as the first tab item
if (this.homeTab == null)
{
this.homeTab = this.TabPages[0];
}
// get initial first display index to a temp variable
int tempFirstIndex = -1;
for (int index = 0; index < this.TabCount; index++)
{
Rectangle currentTabBounds = this.GetTabTextRect(index);
if (currentTabBounds != Rectangle.Empty && tempFirstIndex < 0 && currentTabBounds.X >= 0)
{
tempFirstIndex = index;
break;
}
}
int homeTabIndex = this.TabPages.IndexOf(this.homeTab);
Rectangle homeTabBounds = this.GetTabTextRect(homeTabIndex);
if (homeTabIndex > tempFirstIndex)
{
this.TabPages.Remove(this.homeTab);
this.TabPages.Insert(tempFirstIndex, this.homeTab);
}
else
{
// find the first visible position
// it can not be simply the tempFirstIndex, because in this scenario tab is removed from begining
// tabs are not same in width
while (homeTabBounds != Rectangle.Empty && homeTabBounds.X < 0)
{
homeTabIndex++;
this.TabPages.Remove(this.homeTab);
this.TabPages.Insert(homeTabIndex, this.homeTab);
homeTabBounds = this.GetTabTextRect(homeTabIndex);
}
}
我认为你需要更好地解释你的问题。无论您打开哪个页面,第一个标签页将始终保持第一个页面。 – DotNetHitMan
如果您的显示区域中显示的选项卡多于其显示区域,则会隐藏第一个选项卡。然后,您应该使用滚动控件导航到第一页。希望我已经解释了这个问题。基本上我需要冻结第一个标签。 – user3720148