Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Get rid of rectangle selection in owner draw combobox

81 views
Skip to first unread message

Gilles Arcas

unread,
Jan 28, 2008, 6:21:20 PM1/28/08
to
Hello,

when using a owner draw combobox, the selected item is rounded with a dotted
rectangle. While it's possible to live with it, I would like to know if
there is a way to get rid of the dotted selection rectangle.

Now, if there is no way, one of the problems is that when using colors when
drawing the item, the dotted rectangle seems to be drawn with the
complementary color. For instance, if I write the item in blue, the dotted
rectangle seems to be drawn in yellow. Is it a way to avoid this?

Thanks


Remy Lebeau (TeamB)

unread,
Jan 28, 2008, 7:36:53 PM1/28/08
to

"Gilles Arcas" <gilles...@hotmail.com> wrote in message
news:479e6ab6$1...@newsgroups.borland.com...

> when using a owner draw combobox, the selected item is
> rounded with a dotted rectangle. While it's possible to live
> with it, I would like to know if there is a way to get rid of
> the dotted selection rectangle.

TComboBox calls TCanvas.DrawFocusRect() automatically after the OnDrawItem
event handler exits. You have two choices to prevent the rectangle from
appearing in the final rendering:

1) call Canvas.DrawFocusRect() inside your OnDrawItem handler when the
odFocused flag is present in the State parameter. When the event handler
exits, TComboBox will call DrawFocusRect() again, clearing the rectangle.

2) subclass the ComboBox's WindowProc property to intercept the CN_DRAWITEM
message. You can then remove the ODS_FOCUS flag from the
DRAWITEMSTRUCT.itemState member before passing the message back to the
ComboBox for normal handling.

> one of the problems is that when using colors when drawing the item,
> the dotted rectangle seems to be drawn with the complementary color.
> For instance, if I write the item in blue, the dotted rectangle seems to
> be drawn in yellow.

That is how focus rectangles work in general.


Gambit


Gilles Arcas

unread,
Jan 29, 2008, 3:04:59 PM1/29/08
to
> 1) call Canvas.DrawFocusRect() inside your OnDrawItem handler when the 2)
> subclass the ComboBox's WindowProc property to intercept the CN_DRAWITEM

2) is a little bit beyond my skills with Delphi

1) is ok, although the focus rectangle is not erased in the edit box, even
when testing odComboBoxEdit in State.

Suggestion would be welcome, but this is not really an issue. Thanks a lot.


Andrew Jameson

unread,
Jan 29, 2008, 5:21:57 PM1/29/08
to

"Gilles Arcas" <gilles...@hotmail.com> wrote in message
news:479f86ec$1...@newsgroups.borland.com...

Gilles ... here's a very quick demo of how to get at the CN_DRAWITEM message
by subclassing it and what to do with it ... no focus rectangles !!

Andrew

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;

type
TComboBox = class(StdCtrls.TComboBox) // Temporary subclass to get at
the CNDraw message.
private
procedure CNDrawItem(var Message : TWMDrawItem); message CN_DRAWITEM;
end;

type
TForm1 = class(TForm)
ComboBox1: TComboBox;
procedure ComboBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}

procedure TComboBox.CNDrawItem(var Message : TWMDrawItem);
begin
with Message do
DrawItemStruct.itemState := DrawItemStruct.itemState and not ODS_FOCUS;
inherited;
end; {CNDrawItem}

procedure TForm1.ComboBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
begin
// Do our stuff ...
end;

end.


Gilles Arcas

unread,
Jan 29, 2008, 6:06:35 PM1/29/08
to
> a very quick demo

As you say! Actually, I have almost spent less time coding it than playing
with the focus in my comboboxes to check they were no more dotted
rectangles.

Thanks a lot.
Gilles


0 new messages