开发者

Reorder tabs in TabControl without flickerng

There are multiple examples of modified TabControls on the Internet which allow the user to reorder the tabs using dra开发者_JS百科g and drop. However, all seem to use the following technique:

  • Determine which tab is being dragged
  • Determine the index to which the tab is being dragged
  • Empty the tab page collection and add in the new order

The last step, hoewever, causes the control to flicker alot. Besides this, when there are a lot of tab pages on the tab control, it is rather slow.

Is it possible to swap items (i.e. swap indexes) in a TabPageCollection, without the TabControl flickering?


First of all, you should not empty the tab page collection, just remove the tab you are dragging and insert it at the next position.

Second, while you remove and insert the tabpage, you can suspend the drawing of the TabControl using a little bit of interop, like described in the answer here, by calling SuspendDrawing on your tabcontrol before removing the tabpage and ResumeDrawing after you insert the tabpage at the new position. This should produce a flicker free tab reordering.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜