I'd like a selectable label control, like the one in the screenshot. It could be done with a borderless TEdit, but I was wondering if there is another way that would work with gradient background?
example http://usera.ImageCave.com/brk303/SelectableLabel.png.jpg
To clarify, I'm using a simple PageControl, which since Win XP has gradient drawing, a borderless TEdit placed on a page doesn't blend in perfectly:
Edit on a PageControl http://usera.ImageCave.com/brk303/Gradient.png.jpg
Update:
I managed to get half way there by adding
procedure CNCtlColorStatic(var AMsg: TWMCtlColorStatic); message CN_CTLCOLORSTATIC;
procedure TTransparentEdit.CNCtlColorStatic(var AMsg: TWMCtlColorStatic);
begin
with ThemeServices do
if ThemesEnabled then
begin
SetBkMode(AMsg.ChildDC, Windows.TRANSPARENT);
DrawParentBackground(Handle, AMsg.ChildDC, nil, False);
AMsg.Result := GetStockObject(NULL_BRUSH);
end
else
inherited;
end;
It's now transparent, but something else needs to be done, as painting when text is selected doesn't work properly. The behavior is hard to explain, I will investigate further and update here...
Labels are not editable. TLabel can't even receive the focus, because it does not inherit from TWinControl.
I'd use a TEdit to mimic your screenshot:
object Edit1: TEdit
BorderStyle = bsNone
ParentColor = True
ReadOnly = True
Text = 'Editable label'
end
(you can copy-and-paste the above code to your form)
The normal way is to use a borderless (BorderStyle := bsNone
) and read-only (ReadOnly := true
) TEdit
, possibly combined with Color := clBtnFace
, as you say. However, gradient backgrounds are not common, and there is no out-of-the-box support for such. However, it is not too difficult to do it yourself. I will try to find a simple solution within a few minutes.
Drawing in Windows edit boxes is not trivial. Are you sure you need a gradient background? You could of course write your own control -- writing a TEdit-like control is not really that hard. I have done so a few times. (Proof)
Now I tried it, and it does not work at all under Windows 7 with Aero.
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