Geert Goeteyn
Geert Goeteyn

Reputation: 280

Can I change the caption on the save button of a TSavetextfiledialog in Delphi?

I have a TSavetextfiledialog where the user selects a filename for saving, but the save doesn't happen immediately. Therefore I would like the save button to display "select" rather than "save". Can the caption of the button be changed?

enter image description here

Upvotes: 1

Views: 1225

Answers (1)

Sertac Akyuz
Sertac Akyuz

Reputation: 54802

Since this is an old style common file open dialog, you can use CDM_SETCONTROLTEXT message on the item having IDOK identifier for the parent of the VCL's dialog handle. For IDs of other items, see documentation on Explorer-Style Control Identifiers. Here is calling it in the OnShow event handler:

uses
  commdlg;

procedure TForm2.SaveTextFileDialog1Show(Sender: TObject);
begin
  SendMessage(GetParent(SaveTextFileDialog1.Handle),
      CDM_SETCONTROLTEXT, IDOK, NativeUInt(PChar('MyCaption')));
end;

The dialog is changing the button text when you select a folder to 'Open', when the selection is not a folder, your custom caption is restored.

Upvotes: 3

Related Questions