![]() |
|
|
|||||||
| Регистрация | << Правила форума >> | FAQ | Пользователи | Календарь | Поиск | Сообщения за сегодня | Все разделы прочитаны |
![]() |
|
|
Опции темы | Поиск в этой теме | Опции просмотра |
|
#1
|
|||
|
|||
|
Собственно вопрос как сделать свою рамку выделения у listbox
Код:
procedure TMainApl.ListBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
begin
With (Control as TListBox) do begin
if odSelected in State then
if Index mod 2 = 0 then begin
DrawFocusRect((Control as TListBox).Canvas.Handle, Rect);
canvas.Pen.Width:=3;
canvas.Pen.Color:=clblue;
canvas.Brush.Color:=clred
end else begin
DrawFocusRect((Control as TListBox).Canvas.Handle, Rect);
canvas.Pen.Width:=3;
canvas.Pen.Color:=clblue;
canvas.Brush.Color:=clyellow;
end
else begin
canvas.Pen.Width:=0;
canvas.Pen.Color:=color;
canvas.Brush.Color:=color;
end;
canvas.FillRect(rect);
DrawText(Canvas.Handle, PChar(Items[Index]), Length(Items[Index]), Rect,
Control.DrawTextBiDiModeFlags(DT_SINGLELINE or DT_VCENTER or DT_NOPREFIX));
end;
end; |
|
#2
|
||||
|
||||
|
Код:
With (Control as TListBox) do begin
if odSelected in State then
//if Index mod 2 = 0 then
begin
DrawFocusRect((Control as TListBox).Canvas.Handle, Rect);
canvas.Pen.Width:=3;
canvas.Pen.Color:=clblue;
canvas.Brush.Color:=clred
// end else
// begin
// DrawFocusRect((Control as TListBox).Canvas.Handle, Rect);
// canvas.Pen.Width:=3;
// canvas.Pen.Color:=clblue;
// canvas.Brush.Color:=clyellow;
end
else begin
canvas.Pen.Width:=0;
canvas.Pen.Color:=color;
canvas.Brush.Color:=color;
end;
canvas.FillRect(rect);
DrawText(Canvas.Handle, PChar(Items[Index]), Length(Items[Index]), Rect,
Control.DrawTextBiDiModeFlags(DT_SINGLELINE or DT_VCENTER or DT_NOPREFIX));
end; |
|
#3
|
|||
|
|||
|
Вариант уже пробывал не кактит. Темболее что вывод текста нужно делать через textout так как в будущем я еще и картинки буду отрисовывать рамку надо рисовать через rectangle но без багов (следы после рамки) у меня чет не получается
Последний раз редактировалось Alexandr_17_10, 11.07.2014 в 10:36. |
|
#5
|
|||
|
|||
|
function DrawIcon; external user32 name 'DrawIcon';
А есть аналогичная только для bitmap'ов |
|
#6
|
|||
|
|||
|
Код:
procedure TMainApl.ListBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
var bmp:TBitmap;
begin
With (Control AS TlistBox) do begin
if odFocused in State then
if index mod 2 = 0 then
canvas.Brush.Color:=clRed
else
canvas.Brush.Color:=clYellow
else
canvas.Brush.Color:=color;
canvas.Font.Color:=canvas.Brush.Color xor RGB(255, 255, 255);
canvas.FillRect(rect);
bmp:=TBitmap.Create;
Imagelist1.GetBitmap(2, bmp);
Canvas.Draw(rect.Left, rect.Top - font.Size + (ItemHeight div 2),bmp);
Canvas.TextOut(rect.Left+bmp.Width+2, rect.Top - font.Size + (ItemHeight div 2),
Items.Strings[index]);
if odFocused in State then
DrawFocusRect(Canvas.Handle, Rect);
end;
end; |