Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > Delphi: Общие вопросы > ListBox


Автор: z-END 19.1.2005, 19:38
вот кусок кода:
Код

if odSelected in state then
 begin
  Brush.Color := clWindow;
  Pen.Color := clWindow;
  FillRect (Rect);
 {...}
end
else
begin
  Brush.Color := clWindow;
  Pen.Color := clWindow;
  FillRect (Rect);
  {...}
end;

Но при выделении Итема вокруг него отображается граница. как ее затереть?
ЗЫ пробывал увеличивать р-ры Rect ( Dec (Rect.Top,2) и т.п. не помогло)

Автор: s-mike 19.1.2005, 21:37
Дарю свой компонент. Позволяет разрешить/запретить отображение фокусирующей рамки:
Код

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.

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)