Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
冻结C#.net选项卡控件中的第一个选项卡_C#_.net_Tabs_Freeze - Fatal编程技术网

冻结C#.net选项卡控件中的第一个选项卡

冻结C#.net选项卡控件中的第一个选项卡,c#,.net,tabs,freeze,C#,.net,Tabs,Freeze,有没有办法冻结C#.net选项卡控件的第一个选项卡 我有一个选项卡控制器,可以有许多选项卡。如果用户正在滚动,则第一个选项卡应保持在第一个位置,其余选项卡应移动 我已经尝试过使用在绘制方法中移除和插入选项卡来完成此操作。但在我尝试删除和添加第一页时,似乎有时会出现索引问题 // For the first time home tab comes as the first tab item if (this.homeTab == null)

有没有办法冻结C#.net选项卡控件的第一个选项卡

我有一个选项卡控制器,可以有许多选项卡。如果用户正在滚动,则第一个选项卡应保持在第一个位置,其余选项卡应移动

我已经尝试过使用在绘制方法中移除和插入选项卡来完成此操作。但在我尝试删除和添加第一页时,似乎有时会出现索引问题

            // 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);
                }
            }
//home选项卡第一次作为第一个选项卡项出现
如果(this.homeTab==null)
{
this.homeTab=this.TabPages[0];
}
//获取临时变量的初始第一个显示索引
int tempFirstIndex=-1;
for(int index=0;index=0)
{
tempFirstIndex=索引;
打破
}
}
int homeTabIndex=this.TabPages.IndexOf(this.homeTab);
矩形homeTabBounds=this.GetTabTextRect(homeTabIndex);
如果(homeTabIndex>tempFirstIndex)
{
this.TabPages.Remove(this.homeTab);
this.TabPages.Insert(tempFirstIndex,this.homeTab);
}
其他的
{
//找到第一个可见的位置
//它不能仅仅是tempFirstIndex,因为在这个场景中,选项卡从一开始就被删除了
//制表符的宽度不同
while(hometabouts!=Rectangle.Empty&&hometabouts.X<0)
{
homeTabIndex++;
this.TabPages.Remove(this.homeTab);
this.TabPages.Insert(homeTabIndex,this.homeTab);
homeTabBounds=this.GetTabTextRect(homeTabIndex);
}
}

我找到了冻结第一个选项卡的方法

上述解决方案的问题是,我试图在paint方法中操纵选项卡页面列表。它导致反复调用paint方法并生成异常

因此,我试图操纵从“this.GetTabTextRect(index)”返回的制表符位置。它工作得很好。但是我还必须编写一些代码来调整选项卡选择逻辑

受保护的矩形GetTabTextRect(int索引) {

//获取原始选项卡位置
矩形tabBounds=this.GetTabRect(索引);
//第一个显示的索引将在绘制方法中计算
//如果等于或小于零,则表示制表符数量未超过显示限制,因此无需操纵制表符
如果(this.firstDisplayedIndex>0)
{
//如果不是第一个标签,我们调整位置
如果(索引>0)
{

如果(index>this.firstDisplayedIndex&&index我认为您需要更好地解释您的问题。无论您在哪个页面上,第一个选项卡页始终保持第一页。如果您的选项卡超过显示区域中显示的选项卡数,则第一个选项卡将隐藏。然后您应该使用滚动控件导航到第一页。希望我已经解释了问题基本上我需要冻结第一个标签。
// gets the original tab position
Rectangle tabBounds = this.GetTabRect(index);

// first displayed index will be calculated in the paint method
// if it is equal or less than to zero means, the number of tabs are not exceeded the display limit. So no need tab manipulating
if (this.firstDisplayedIndex > 0 )
{
    // if it is not first tab we adjust the position
    if (index > 0)
    {
        if (index > this.firstDisplayedIndex && index <= this.lastDisplayedIndex)
        {
            Rectangle prevBounds = this.CurrentTabControl.GetTabRect(this.firstDisplayedIndex);

            // home tab (first tab) bounds will be stored in a global variable when the tab control initializes
            tabBounds.X = tabBounds.X - prevBounds.Width + this.homeTabBounds.Width;
        }
        else if (index == this.firstDisplayedIndex) // we need to free this slot for the first tab (index = 0)
        {
            tabBounds.X -= 1000;
        }
    }
    else
    {
        // first tab position is fixed
        tabBounds.X = 0;
    }
}