Double-clicking a TStaticText on a form copies the caption of that TStaticText to the clipboard. No double-click event is needed.
Steps to reproduce:
I have already submitted a bug report to Embarcadero.
I tried assigning a double-click event to the TStaticTexts. It still copies the caption to the clipboard even though it executes the double-click event.
procedure TForm1.StaticText1DblClick(Sender: TObject);
begin
Edit1.Text := 'Hello';
end;
procedure TForm1.StaticText2DblClick(Sender: TObject);
begin
Edit1.Text := 'World';
end;
This does not happen with TLabel or any other VCL control I have tried.
We have lots of TStaticTexts on our forms for visual design purposes and changing to TLabels is not an option.
Anybody have any ideas on how to prevent this from happening?
This is not a delphi bug, this behaviour is caused by the Windows Static Control
which is created by the TStaticText VCL component.
Starting in Windows Vista, the Static text controls automatically copy their contents to the clipboard when you double-click them if you set the SS_NOTIFY style (the SS_NOTIFY style is set by the CreateParams method of the TCustomStaticText component)
Recomended lecture How do I make it so that users can copy static text on a dialog box to the clipboard easily?
As workaround you can remove the SS_NOTIFY style overriding the CreateParams method like so
type
TStaticText = class(Vcl.StdCtrls.TStaticText)
protected
procedure CreateParams(var Params: TCreateParams); override;
end;
TForm1 = class(TForm)
StaticText1: TStaticText;
private
public
end;
var
Form1: TForm42;
implementation
{$R *.dfm}
{ TStaticText }
procedure TStaticText.CreateParams(var Params: TCreateParams);
begin
inherited;
with Params do
Style := Style and not SS_NOTIFY;
end;
Note : you must be aware if you remove this style from the control you will no receive the STN_CLICKED, STN_DBLCLK, STN_DISABLE, and STN_ENABLE notification codes when the user clicks or double-clicks the control.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With