Дарю свой компонент. Позволяет разрешить/запретить отображение фокусирующей рамки:
| Код | unit NewListBox;
interface
uses SysUtils, Classes, Controls, StdCtrls, Messages, Windows, Graphics;
type TNewListBox = class(TListBox) private FDrawFocusRect: Boolean; procedure CNDrawItem(var Message: TWMDrawItem); message CN_DRAWITEM; procedure SetDrawFocusRect(const Value: Boolean); public constructor Create(AOwner: TComponent); override; published property DrawFocusRect: Boolean read FDrawFocusRect write SetDrawFocusRect default False; end;
procedure Register;
implementation
procedure Register; begin RegisterComponents('MSX Controls', [TNewListBox]); end;
constructor TNewListBox.Create(AOwner: TComponent); begin inherited;
end;
procedure TNewListBox.CNDrawItem(var Message: TWMDrawItem); var State: TOwnerDrawState; begin with Message.DrawItemStruct^ do begin State := TOwnerDrawState(LongRec(itemState).Lo); Canvas.Handle := hDC; Canvas.Font := Font; Canvas.Brush := Brush; if (Integer(itemID) >= 0) and (odSelected in State) then begin Canvas.Brush.Color := clHighlight; Canvas.Font.Color := clHighlightText end; if Integer(itemID) >= 0 then DrawItem(itemID, rcItem, State) else Canvas.FillRect(rcItem); if (odFocused in State) and FDrawFocusRect then Windows.DrawFocusRect(hDC, rcItem); Canvas.Handle := 0; end; end;
procedure TNewListBox.SetDrawFocusRect(const Value: Boolean); begin if FDrawFocusRect <> Value then begin FDrawFocusRect := Value; Invalidate; end; end;
end.
| |