Форум: "KOL";
Текущий архив: 2006.11.19;
Скачать: [xml.tar.bz2];
ВнизProblem ListBox.OnDrawItem Найти похожие ветки
← →
Dodfr (2006-02-02 13:30) [0]Hi,
I have problem in OnDrawItem with DrawIcon that seems not draw correctly 100% time as it should but the TextOut is drawed correcly.
Sometime the icon do not appear at all, sometime it is not fully drawed, the worst is when I move other window over the form owning the ListBox but also when I use mdvToolTip display inside the ListBox.
Any idea ?
Here is part of code I use :
if (odsSelected in ItemState) then
begin
PControl(sender).Canvas.Brush.Color:=clhighlight;
PControl(sender).Canvas.font.color:=clwhite;
end
else
begin
PControl(sender).Canvas.Brush.Color:=clwhite;
PControl(sender).Canvas.font.color:=0;
end;
PControl(sender).Canvas.FillRect(Rect);
PControl(sender).Canvas.Pen.Color:=0;
ImageList1.Draw(3,DC,Rect.Left+2,Rect.Top);
PControl(sender).Canvas.TextOut(Rect.Left+22,Rect.Top+1,ListBoxProfils.Items[ItemIdx]);
← →
ECM © (2006-02-02 21:17) [1]try
1)
if not (odaEntire in DrawAction) then PControl(sender).Canvas.FillRect(Rect);
or
2)
ImageList1.Draw(3,PControl(sender).Canvas.Handle,Rect.Left+2,Rect.Top);
← →
ECM © (2006-02-02 21:19) [2]P.S.
or just:
// PControl(sender).Canvas.FillRect(Rect);
// PControl(sender).Canvas.Pen.Color:=0;
← →
Dodfr (2006-02-03 01:13) [3]Thanx a lot both solutions works !
But, I would like to understand why it did not work in order to avoid future troubles so if you could answer these questions :
Why DC parameter was wrong for .Draw as it was the one passed to the Event and it is a DC that should be passed to function ?
Why FillRect had to be drawn only if not odaEntire ? I don"t understand why it avoid the .Draw to work all the time and not the .TextOut.
Thank you for your answer ECM.
← →
ECM © (2006-02-04 13:44) [4]
> I don"t understand why it avoid the .Draw to work all the
> time and not the .TextOut.
Because here "DC" it is not equal " Canvas. Handle ".
In occasion of " odaEntire in DrawAction " I was mistaken, excuse. "odaEntire" is present practically always and "FillRect" it was never caused.
There are three variants of the decision of a problem:
1) To use exclusively DC:if (odsSelected in ItemState) then begin
hbr := GetSysColorBrush(COLOR_HIGHLIGHT);
SetTextColor(DC,Color2Rgb(clwhite));
SetBkColor(DC,GetSysColor(COLOR_HIGHLIGHT));
end else begin
hbr := GetSysColorBrush(COLOR_WINDOW);
SetTextColor(DC,Color2Rgb(clBlack));
SetBkColor(DC,GetSysColor(COLOR_WINDOW));
end;
FillRect( DC, Rect, hbr);
ImageList1.Draw(3,DC,Rect.Left+2,Rect.Top);
TextOut(DC,Rect.Left+22,Rect.Top+1,@ListBox1.Items[ItemIdx][1],Length(ListBox1.Items[ItemIdx]));
2) To use exclusively Canvas:
if (odsSelected in ItemState) then begin
PControl(sender).Canvas.Brush.Color:=clhighlight;
PControl(sender).Canvas.font.color:=clwhite;
end else begin
PControl(sender).Canvas.Brush.Color:=clwhite;
PControl(sender).Canvas.font.color:=0;
end;
PControl(sender).Canvas.FillRect(Rect);
ImageList1.Draw(3,PControl(sender).Canvas.Handle,Rect.Left+2,Rect.Top);
PControl(sender).Canvas.TextOut(Rect.Left+22,Rect.Top+1,ListBox1.Items[ItemIdx]);
3) Mixed :))
But, in the beginning procedures to make the following:
PControl(Sender).Canvas.Handle := DC;
The mechanism of carry drawn on " Canvas. Handle " on DC in case of when " Canvas. Handle <> DC " I up to the end have not understood. Probably Vladimir will help to understand a mechanism?
← →
Thaddy (2006-02-04 16:20) [5]Mixed :))
Brilliant!
← →
Vladimir Kladov (2006-02-05 10:12) [6]Too long to discuss. Briefly: Canvas gets correct DC while WM_PAINT processing, on a time while it is handling. But OnDrawItem goes another way. Anyway DC passed to the handler is correct DC so your last solve is enough.
← →
Dodfr (2006-02-05 21:18) [7]Many thanks everybody for this complete explanation, I hope it will be usefull to other guys because this kind of information that take too much time to look for thru MSDN documentation.
Regards
Страницы: 1 вся ветка
Форум: "KOL";
Текущий архив: 2006.11.19;
Скачать: [xml.tar.bz2];
Память: 0.46 MB
Время: 0.044 c