Interaction
Interaction settings control how users add, close, edit, reorder, and navigate tabs. Enable only the actions that match the workflow: document tabs often need close and reorder support, while navigation tabs are usually fixed.
Reordering tabs
Set Interaction.Reorder to True when users may drag tabs into a new order. Use OnBeforeReorderTab to block protected tabs or keep fixed tabs at the beginning of the strip.
Inline editing
Set Interaction.Editing to True to let users rename tabs in place. The inplace editor workflow can be customized with OnBeforeOpenInplaceEditor, OnOpenInplaceEditor, OnGetInplaceEditor, OnCustomizeInplaceEditor, OnGetInplaceEditorRect, OnBeforeUpdateTab, OnUpdateTab, and OnCloseInplaceEditor.
Keyboard behavior
| Property | Description |
|---|---|
InsertTabWithKeyboard |
Allows keyboard insertion when insert mode is enabled |
CloseTabWithKeyboard |
Allows keyboard close or hide actions |
SelectTabOnFocus |
Selects a tab when it receives focus |
SelectTabOnScroll |
Selects the tab reached by previous/next navigation |
SelectTabOnInsert |
Selects a newly inserted tab |
URL handling
When Interaction.AutoOpenURL is True, clicking an anchor in HTML tab text opens the URL automatically. Use OnAnchorTabClick when the application should handle the anchor itself. See HTML and anchors for the full workflow.
Tab list button
The tab list button gives users a way back to hidden tabs. Use it with Options.CloseAction := ttcaHide or when tabs may be hidden by setting TabVisible to False.
Insert mode
Options.InsertMode controls where the insert action appears.
| Value | Description |
|---|---|
timNone |
No built-in insert button |
timTab |
Insert action appears as a tab |
timMenu |
Insert action appears in the menu button area |
Close mode
Options.CloseMode controls where the close action appears.
| Value | Description |
|---|---|
tcmNone |
No built-in close button |
tcmTab |
Close buttons appear on tabs |
tcmMenu |
Close action appears in the menu button area |
Handling tab events
Use the before-events to validate an action and the after-events to update application state after the tab set has changed.
procedure TForm1.FormCreate(Sender: TObject);
begin
TMSFNCTabSet1.Options.CloseMode := tcmTab;
TMSFNCTabSet1.Options.CloseAction := ttcaHide;
TMSFNCTabSet1.Options.InsertMode := timTab;
TMSFNCTabSet1.Options.TabListButton := True;
TMSFNCTabSet1.Interaction.Reorder := True;
TMSFNCTabSet1.Interaction.Editing := True;
TMSFNCTabSet1.Interaction.CloseTabWithKeyboard := True;
TMSFNCTabSet1.Interaction.InsertTabWithKeyboard := True;
TMSFNCTabSet1.Interaction.SelectTabOnInsert := True;
end;
procedure TForm1.TMSFNCTabSet1BeforeCloseTab(Sender: TObject;
ATabIndex: Integer; var ACloseAction: TTMSFNCTabSetTabCloseAction);
begin
if ATabIndex = 0 then
ACloseAction := ttcaNone
else
ACloseAction := ttcaHide;
end;
procedure TForm1.TMSFNCTabSet1BeforeReorderTab(Sender: TObject;
ACurrentTabIndex, ANewTabIndex: Integer; var ACanReorder: Boolean);
begin
ACanReorder := (ACurrentTabIndex > 0) and (ANewTabIndex > 0);
end;
Combining reordering, inline editing, and close behavior
Enable drag reorder, inline rename, and hide-on-close with the tab list button so users can restore hidden tabs:
procedure TForm1.FormCreate(Sender: TObject);
begin
TMSFNCTabSet1.Interaction.Reorder := True; // drag to reorder
TMSFNCTabSet1.Interaction.Editing := True; // rename in place
TMSFNCTabSet1.Interaction.CloseTabWithKeyboard := True;
TMSFNCTabSet1.Options.CloseMode := tcmTab; // close hides...
TMSFNCTabSet1.Options.CloseAction := ttcaHide;
TMSFNCTabSet1.Options.TabListButton := True; // ...and can be restored
TMSFNCTabSet1.OnBeforeUpdateTab := DoBeforeRename;
TMSFNCTabSet1.OnBeforeReorderTab := DoBeforeReorder;
end;
procedure TForm1.DoBeforeRename(Sender: TObject; ATabIndex: Integer;
var AText: String; var ACanUpdate: Boolean);
begin
// Reject an empty tab name.
ACanUpdate := Trim(AText) <> '';
end;
procedure TForm1.DoBeforeReorder(Sender: TObject; ACurrentTabIndex,
ANewTabIndex: Integer; var ACanReorder: Boolean);
begin
// Keep the first tab pinned at position 0.
ACanReorder := ANewTabIndex > 0;
end;
Related API
TTMSFNCTabSet-Interaction,Options, and tab events
See also
- Tabs - tab properties, badges, bitmaps, progress indicators, and close buttons
- Appearance - menu button appearance and tab layout