| Код | var MyIcons: HIMAGELIST; OldTestHit: TListItem = nil;//для выделения TestHit: TListItem = nil;//для выделения ...
|
| Код | предводительно создать и запихнуть картинки procedure TForm1.FormCreate(Sender: TObject); var i:integer; begin myIcons := ImageList_Create(GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), ILC_COLOR16 or ILC_MASK, IconList.Count, 20); for i := 0 to IconList.Count - 1 do begin IconList.GetIcon(i, icon); ImageList_AddIcon(myIcons, icon.Handle);//по другому он не хочет закидывать end; ---------
VAR IconHeight: Integer;//размер картинки FontHeight: Integer;//размер шрифта r: TRect; DC: HDC; img: Integer;//номер картинки Fg, Style: Cardinal;//для режимов BEGIN Sender.Canvas.Font.Name := 'Tahoma'; r := Rect; r.BottomRight.X := Sender.Canvas.TextWidth(Item.Caption) + 23 + 2; r.TopLeft.X := 21; img:=0;//во всех итемах
if (TestHit <> nil) and (TestHit = Item) and (not (odSelected in State)) then begin Sender.Canvas.Brush.Color := listview1.Color; Sender.Canvas.Font.Color := clnavy; Fg := GetSysColor(CLR_DEFAULT);// COLOR_MENU Style := ILD_BLEND25; end else begin if odSelected in State then begin Sender.Canvas.Brush.Color := listview1.Color; Sender.Canvas.Font.Color := clnavy;//clWhite; Fg := GetSysColor(CLR_DEFAULT); Style := ILD_BLEND50; end else begin Sender.Canvas.Brush.Color := listview1.Color; Sender.Canvas.Font.Color := clBlue; if img = ICON_OFFLINE then Sender.Canvas.Font.Color := clRed; Fg := CLR_DEFAULT; Style := ILD_NORMAL;
end; end;
if (TestHit <> OldTestHit) and (OldTestHit <> nil) and (OldTestHit = Item) then begin if odSelected in State then begin Sender.Canvas.Brush.Color := listview1.Color; ///clnavy Sender.Canvas.Font.Color := listview1.Font.Color; Fg := GetSysColor(CLR_DEFAULT); // Style := ILD_BLEND50; end else begin Sender.Canvas.Brush.Color := listview1.Color; Sender.Canvas.Font.Color := clBlue; if img = ICON_OFFLINE then Sender.Canvas.Font.Color := clRed; Fg := CLR_DEFAULT; Style := ILD_NORMAL; end; end; Sender.Canvas.FillRect(r); IconHeight := 16; FontHeight := Sender.Canvas.TextHeight('Xy'); DC := GetDC(Item.Handle);
ImageList_DrawEx(MYIcons, img, DC, Rect.Left + 3, Rect.Top + (LVItemHeight - IconHeight) div 2, 0, 0, CLR_NONE, Fg, Style); ReleaseDC(Item.Handle, DC); Sender.Canvas.TextOut(Rect.left + 23, Rect.Top + (LVItemHeight - FontHeight) div 2, Item.caption; ... end;
procedure TForm1.ListView1SelectItem(Sender: TObject; Item: TListItem; Selected: Boolean); var rc: TRect; begin OldTestHit := TestHit; if ListView1.IsEditing then Exit; if OldTestHit = nil then SetCapture(ListView1.Handle) else if TestHit = nil then ReleaseCapture; if OldTestHit <> nil then begin rc := OldTestHit.DisplayRect(drBounds); InvalidateRect(ListView1.Handle, @rc, True); end; if TestHit <> nil then begin rc := TestHit.DisplayRect(drBounds); InvalidateRect(ListView1.Handle, @rc, True); end; end;
|
|