Главная страница
Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2006.11.19;
Скачать: CL | DM;

Вниз

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 вся ветка

Текущий архив: 2006.11.19;
Скачать: CL | DM;

Наверх




Память: 0.48 MB
Время: 0.054 c
6-1148946937
nikitian
2006-05-30 03:55
2006.11.19
Проблема с кодировкой в indySMTP


2-1162207666
pathfinder
2006-10-30 14:27
2006.11.19
командная строка..


15-1162387290
Ученик чародея.
2006-11-01 16:21
2006.11.19
Что вы обычно используете abstract или dynamic методы?


2-1162501134
dRake
2006-11-02 23:58
2006.11.19
Пара вопросов (+)


2-1162204791
Монг
2006-10-30 13:39
2006.11.19
Глюк с удалением