简体   繁体   English

在多行 tabcontrol 中从下到上移动标签页时跳动

[英]Tabpages are jumping when moving them from bottom to top in multiline tabcontrol

We he a draggable tabpages, the implementation is similar to the approaches suggested in the topic How to make TabPages draggable?我们是一个可拖动的tabpages,其实现类似于How to make TabPages draggable主题中建议的方法 . . I think that this is not a matter of our changes, since I tried the proposed approaches on pure tab control in a separate project and noticed exactly the same behavior.我认为这与我们的更改无关,因为我在一个单独的项目中尝试了纯选项卡控件的建议方法,并注意到完全相同的行为。 Has anyone faced a similar problem?有没有人遇到过类似的问题? Is there any reasonable solution?有什么合理的解决办法吗? It seems to me, is not a good idea to disallowing drawing, because then it will not be visible where the tab is moving.在我看来,禁止绘图并不是一个好主意,因为那样在选项卡移动的地方就看不到了。

A video recording of the problem问题的视频记录在此处输入图片说明

Link to minimal reproducable example https://drive.google.com/file/d/122u3jcTmqEOl4LcmLI4n3cEvIlds328B/view?usp=sharing链接到最小可重现示例https://drive.google.com/file/d/122u3jcTmqEOl4LcmLI4n3cEvIlds328B/view?usp=sharing

The bottom-most row of tabs is the active row.最底部的选项卡行是活动行。 Clicking/swapping a tab on an upper row moves that entire row to the bottom-most row.单击/交换上一行上的选项卡会将整行移动到最下一行。 This is what is causing the jitter.这就是造成抖动的原因。

If you are dragging a TabPage along the active row then it is fine to swap the index locations in the TabPageCollection .如果您沿活动行拖动TabPage ,则可以交换TabPageCollection的索引位置。 However, as soon as an upper row tab is involved, the TabControl re-orders the rows.但是,只要涉及上一行选项卡, TabControl重新排列行。

One possible idea is to only change the TabPage.Text property.一种可能的想法是只更改TabPage.Text属性。 However, then each tab rectangle width needs to be locked, otherwise it will probably cause a jitter problem.但是,那么每个tab矩形宽度都需要锁定,否则很可能会导致抖动问题。 I was playing around with the text renaming idea, the code is below.我在玩文本重命名的想法,代码如下。 If just the text is changed, the tab highlighting also needs to be made smarter so that the destination tab appears highlighted, and the source tab no longer appears highlighted.如果仅更改文本,还需要更智能地突出显示选项卡,以便目标选项卡突出显示,而源选项卡不再突出显示。 Finally, when the drag operation is over is when the actual swap would happen, which would make the source tab's row the active row (not done in the code).最后,当拖动操作结束时将发生实际交换,这将使源选项卡的行成为活动行(未在代码中完成)。

private static void swapTabPages2(TabControl tc, TabPage src, TabPage dst, DragTabData data) {
    TabPageCollection tabs = tc.TabPages;
    int n = tabs.Count;
    int index_src = tabs.IndexOf(src);
    int index_dst = tabs.IndexOf(dst);

    if (index_dst >= index_src) {
        for (int i = 0; i < index_src; i++)
            tabs[i].Text = data.OrigText[i]; // OrigText stores each tab's original Text just before this.DoDragDrop(...) is called
        for (int i = index_dst + 1; i < n; i++)
            tabs[i].Text = data.OrigText[i];

        for (int i = index_src; i < index_dst; i++)
            tabs[i].Text = data.OrigText[i+1];

        tabs[index_dst].Text = data.OrigTabText;
    }
    else {
        for (int i = 0; i < index_dst; i++)
            tabs[i].Text = data.OrigText[i];
        for (int i = index_src + 1; i < n; i++)
            tabs[i].Text = data.OrigText[i];

        for (int i = index_src; i > index_dst; i--)
            tabs[i].Text = data.OrigText[i-1];

        tabs[index_dst].Text = data.OrigTabText;
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM