Table of Contents

In-place Editing

TTMSFNCLabelEdit displays formatted label text and can switch into an embedded edit control. Use it for editable names, captions, tags, or settings where a separate dialog would interrupt the workflow.

Label edit

Configure Editing

The control inherits formatted text rendering and adds an Edit control plus accept and cancel buttons. Set Editable to allow user edits, or set it to False for read-only label behavior.

procedure TForm1.ConfigureLabelEdit;
begin
  TMSFNCLabelEdit1.Text := 'Project name';
  TMSFNCLabelEdit1.Editable := True;
  TMSFNCLabelEdit1.HorizontalTextAlign := gtaLeading;
end;

procedure TForm1.StartLabelEdit;
begin
  TMSFNCLabelEdit1.EditMode := True;
end;

Commit and Cancel

When the user accepts the edit, OnAccept fires after the text has been committed. When the user cancels, the previous text is restored and OnCancel fires.

procedure TForm1.ConfigureLabelEditEvents;
begin
  TMSFNCLabelEdit1.OnAccept := TMSFNCLabelEdit1Accept;
  TMSFNCLabelEdit1.OnCancel := TMSFNCLabelEdit1Cancel;
end;

procedure TForm1.TMSFNCLabelEdit1Accept(Sender: TObject);
begin
  Caption := TMSFNCLabelEdit1.Text;
end;

procedure TForm1.TMSFNCLabelEdit1Cancel(Sender: TObject);
begin
  StatusLabel.Text := 'Edit canceled.';
end;

Edit Lifecycle

Use OnEditStart and OnEditEnd for UI state changes such as highlighting the edited row or enabling validation helpers. OnEditKeyDown is available when keyboard handling needs to intercept a key before the edit completes.

Button Styling

AcceptButton and CancelButton are image controls. Their strokes are exposed through AcceptButtonStroke and CancelButtonStroke, and they inherit the label edit BitmapContainer for shared bitmap usage.

procedure TForm1.ConfigureLabelEditButtons;
begin
  TMSFNCLabelEdit1.BitmapContainer := TMSFNCBitmapContainer1;
  TMSFNCLabelEdit1.AcceptButtonStroke.Color := gcGreen;
  TMSFNCLabelEdit1.CancelButtonStroke.Color := gcRed;
end;

Combining in-place editing, commit/cancel, and lifecycle events

The following example enables editing on double-click, validates the new text before accepting, uses lifecycle events to highlight the edited row, and styles the buttons from a shared bitmap container:

procedure TForm1.lblNameDblClick(Sender: TObject);
begin
  TMSFNCLabelEdit1.StartEdit;
end;

procedure TForm1.TMSFNCLabelEdit1EditStart(Sender: TObject);
begin
  Panel1.Color := clHighlight; // highlight the row while editing
end;

procedure TForm1.TMSFNCLabelEdit1EditEnd(Sender: TObject);
begin
  Panel1.Color := clBtnFace;
end;

procedure TForm1.TMSFNCLabelEdit1Accept(Sender: TObject; var AText: string;
  var ACanAccept: Boolean);
begin
  ACanAccept := Trim(AText) <> '';
  if not ACanAccept then
    ShowMessage('Name cannot be blank.');
end;

procedure TForm1.TMSFNCLabelEdit1Cancel(Sender: TObject);
begin
  // Text restored to previous value automatically
end;