使用拖放移动 TabControl TabItems

Move TabControl TabItems using Drag and Drop

我正在使用 Delphi XE7 Firemonkey。

我想移动 TTabControl 组件的 TTabItems,就像现代 Web 浏览器处理它们的选项卡一样。

我找到了一些教程,但那些是针对 VCL 的 (http://www.swissdelphicenter.com/de/showcode.php?id=963)

我还发现了 TChromeTabs (http://www.easy-ip.net/tchrometabs.html),但这也是专为 VCL 制作的。

非常感谢任何帮助

您首先需要将每个 TTabItem 上的 DragMode 设置为 dmAutomatic。从那里一个 TTabItems OnDragDrop 过程是你需要编写代码的。我提供了有关如何获取源和目标 TTabItems 的快速片段。当执行 "drop" 时,您想要实现的目标由您决定:

OnDragDrop

//This is your TTabItem that is being dragged
TTabItem(Data.Source).Index//Index of this object in your TTabControl
//This is your TTabItem that is being "dropped" to
TTabItem(Sender).Index//Index of this object in your TTabControl

此外,如果您将此代码分配给 TTabItem 的 OnDragMove,您将获得一个蓝色的拖动高亮显示,显示当前所在的选项卡:

OnDragMove

Operation:=TDragOperation.Move;

希望对您有所帮助