Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Show TextHint in combobox with csOwnerDrawFixed



Permlink Replies: 2 - Last Post: Mar 22, 2018 1:46 AM Last Post By: Michael Rabatsc...
Michael Rabatsc...

Posts: 125
Registered: 1/22/07
Show TextHint in combobox with csOwnerDrawFixed
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 21, 2018 4:43 AM
Hi!

How can I use the TextHint property in a combobox if csOwnerDrawFixed is
used. Or better how can I draw the combobox area with a default value if
itemindex = -1

Or if that is not possible:
How can I use TComboBoxEx, dropdownlist and show some TextHint (e.g.
please select something) in the field prior to a selection aka the
itemindex is -1

kind regards
Mike

I'm using Delphi 2010 if that is an issue...

Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Show TextHint in combobox with csOwnerDrawFixed
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 21, 2018 8:21 AM   in response to: Michael Rabatsc... in response to: Michael Rabatsc...
Michael Rabatscher wrote:

How can I use the TextHint property in a combobox if csOwnerDrawFixed
is used.

You can't. You will have to custom draw the text yourself.

Or better how can I draw the combobox area with a default value if
itemindex = -1

Look at the Win32 API DrawFrameControl() and DrawThemeBackground/Ex()
functions.

How can I use TComboBoxEx, dropdownlist and show some TextHint (e.g.
please select something) in the field prior to a selection aka the
itemindex is -1

You can't, because DropDownList doesn't have an edit field. I suggest
you add an extra item to the list for the text you want, initialize the
ItemIndex to that item, and don't let the user select that item.

--
Remy Lebeau (TeamB)
Michael Rabatsc...

Posts: 125
Registered: 1/22/07
Re: Show TextHint in combobox with csOwnerDrawFixed
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 22, 2018 1:46 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Am 21.03.2018 um 16:21 schrieb Remy Lebeau (TeamB):
You can't, because DropDownList doesn't have an edit field. I suggest
you add an extra item to the list for the text you want, initialize the
ItemIndex to that item, and don't let the user select that item.

Thanks for the hints!

Actually I followed this approach now which seems to work quite well for me:

in FormCreate

fOldWndcboProc := cboBTDevices.WindowProc;
cboBTDevices.WindowProc := BTCBOWndProc;

procedure TfrmConfigMK5.BTCBOWndProc(var Message: TMessage);
var x, y : integer;
begin
fOldWndcboProc(message);

if (message.Msg = WM_PAINT) and (cboBTDevices.ItemIndex < 0) then
begin
cboBTDevices.Canvas.Font.Color := clLtGray;

x := cboBTDevices.ClientRect.Left + 10;
y := (cboBTDevices.ClientRect.Top +
cboBTDevices.ClientRect.Bottom) div 2;
y := y - cboBTDevices.Canvas.TextHeight('A') div 2;

cboBTDevices.Canvas.Brush.Style := bsClear;
cboBTDevices.Canvas.TextOut( x, y, sCapSelRecorder );
end;
end;

This immitates a texthint as I need it... When the recorder is selected
I try to connect to our recorders by bluetooth.

kind regards
Mike

Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02