-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