Главная страница
    Top.Mail.Ru    Яндекс.Метрика
Форум: "Начинающим";
Текущий архив: 2006.11.12;
Скачать: [xml.tar.bz2];

Вниз

OverDraw и TreeView   Найти похожие ветки 

 
markers ©   (2006-10-28 01:43) [0]

Имею заполненое дерево  и мне нужно у некоторых итемов "подписать" другим цветом текст, Когда я использовал ListBox я это делал так:
[CODE]var catSel:Integer;
begin
 with (Control as TListBox).Canvas do
  begin
   if odd(Index-1) then Brush.Color:=$FFFFFF
   else Brush.Color:=$F5F5F5;
   if (odSelected in State) or (odFocused in State) or (odComboBoxEdit in State) Then
    begin
     Brush.Color:=clNavy;
     Brush.Style:=bsSolid;
     Font.Color:=clWhite;
    end
   else Font.Color:=(Control as TListBox).Font.Color;
   FillRect(Rect);
   TextOut(Rect.Left+2,Rect.Top+1,CategoryList.Items.Strings[index]);
   if (CatRule = "NEWMES") or (CatRule = "OLDMES") Then
    begin
     catSel:=CategoryName.IndexOf(CategoryList.Items.Strings[index]);
     if (CatRule = "NEWMES") and (CategoryST.Strings[catSel] = "1") Then
      begin
       Font.Color:=CatColor;
       Font.Style:=[fsItalic];
       TextOut (Rect.Left+TextWidth(CategoryList.Items.Strings[index])+5, Rect.Top+1, CatMes);
       if TextWidth(CategoryList.Items.Strings[index]+"  "+CatMes) > MaxLen Then
        begin
         MaxLen:=TextWidth(CategoryList.Items.Strings[index]+"  "+CatMes);
         SendMessage(CategoryList.Handle, LB_SETHORIZONTALEXTENT, MaxLen+5, Longint(0));
        end;
      end
     else if (CatRule = "OLDMES") and (CategoryST.Strings[catSel] = "0") Then
      begin
       Font.Color:=CatColor;
       Font.Style:=[fsItalic];
       TextOut (Rect.Left+TextWidth(CategoryList.Items.Strings[index])+5, Rect.Top+1, CatMes);
       if TextWidth(CategoryList.Items.Strings[index]+"  "+CatMes) > MaxLen Then
        begin
         MaxLen:=TextWidth(CategoryList.Items.Strings[index]+"  "+CatMes);
         SendMessage(CategoryList.Handle, LB_SETHORIZONTALEXTENT, MaxLen+5, Longint(0));
        end;
      end;
    end
   else
    if TextWidth(CategoryList.Items.Strings[index]) > MaxLen Then
     begin
      MaxLen:=TextWidth(CategoryList.Items.Strings[index]);
      SendMessage(CategoryList.Handle, LB_SETHORIZONTALEXTENT, MaxLen+5, Longint(0));
     end;
  end;
end;[/CODE]
И никак толком не могу реализовать тоже самое с TreeView (Сделал только разноцветность выделением цветом всего итема)


 
Gero ©   (2006-10-28 01:50) [1]

OnCustomDrawItem


 
markers ©   (2006-10-28 01:53) [2]

Gero ©   (28.10.06 1:50) [1]
Да уж знаю..... Но неполучается ничего :(


 
Gero ©   (2006-10-28 01:57) [3]

А как пробовал и что не получилось?


 
RASkov   (2006-10-28 02:26) [4]

procedure TForm1.TreeView1CustomDrawItem(Sender: TCustomTreeView; Node: TTreeNode;
 State: TCustomDrawState; var DefaultDraw: Boolean);
var
 NodeRect: TRect;
begin
 with TreeView1.Canvas do begin
  NodeRect := Node.DisplayRect(True);
  FillRect(NodeRect);
  if cdsSelected in State then begin
   Font.Color:=clYellow;
   Font.Style:=[fsBold];
   Brush.Color := clBlack;
  end else begin
   if Node.Text ="NEWMES" then Font.Color:=clLime
    else if Node.Text ="OLDMES" then Font.Color:=clRed
   else Font.Color:=clNavy;
  end;
  TextOut(NodeRect.Left, NodeRect.Top, Node.Text);
 end;
end;


 
markers ©   (2006-10-28 02:55) [5]

RASkov   (28.10.06 2:26) [4]
В вашем примере выделяется вся строка, это я и так сделал, а мне нужно "дописать" строку другим цветом!


 
markers ©   (2006-10-28 03:01) [6]

Gero ©   (28.10.06 1:57) [3]
Пробовал всяко разно, ну примерно так:
procedure TMainForm.CatsViewCustomDrawItem(Sender: TCustomTreeView;
 Node: TTreeNode; State: TCustomDrawState; var DefaultDraw: Boolean);
var Rect:TRect;
   Rect2:TRect;
   inc:Integer;
   cattype:string;
begin
 if CatsView.Items.Count = 0 then Exit;
 with TTreeView(Sender).Canvas do
  begin
   Font.Color:=CatsView.Font.Color;
   Font.Style:=[];
   DefaultDraw:=True;
   Rect:=Node.DisplayRect(False);
   Rect2:=Node.DisplayRect(True);
   if Node.Level > 0 then
    begin
     inc:=Node.Index+Node.Parent.Index;
    end
   else inc:=Node.Index-1;
   if odd(inc) then Brush.Color:=$FFFFFF
   else Brush.Color:=$F5F5F5;
   if (cdsSelected in State) or (cdsFocused in State) Then
    begin
     Brush.Color:=clNavy;
     Brush.Style:=bsSolid;
     Font.Color:=clWhite;
     Font.Style:=[];
    end
   else Font.Color:=CatsView.Font.Color;
   FillRect(Rect);
   FillRect(Rect2);
   TextOut(Rect2.Left+2,Rect2.Top+1,Node.Text);
   if Integer(Node.Data) > 0 then
    cattype:=GetCatStat(IntToStr(Integer(Node.Data)))
   else
    begin
     if Integer(Node.Data) = -1 then
      cattype:="New"
     else if Integer(Node.Data) = -2 then
      cattype:="Spec";
    end;
   if cattype <> "Normal" then
    begin
     Font.Color:=clRed;
     Font.Style:=[fsItalic];
     if cattype = "New" then
      begin
       Font.Color:=clRed;
       TextOut (Rect2.Left+TextWidth(Node.Text)+7, Rect2.Top+1, "New!");
      end
     else if cattype = "Spec" then
      begin
       Font.Color:=clGreen;
       TextOut (Rect2.Left+TextWidth(Node.Text)+7, Rect2.Top+1, "Сп!");
      end;
    end;
  end;
end;


 
markers ©   (2006-10-28 03:03) [7]

Кстати можно вообще забить на то что там рисует TreeView, но тогда слишком много чего рисовать надо будет (Линии, +/- и т.д.)


 
RASkov   (2006-10-28 03:06) [8]

> [5] markers ©   (28.10.06 02:55)

Ну может ченить так:
...
  TextOut(NodeRect.Left, NodeRect.Top, Node.Text);
  Font.Color:=clBlue;
  TextOut(NodeRect.Left+TextWidth(Node.Text), NodeRect.Top, " blabla");
...

Сейчас еще подумаю....


 
RASkov   (2006-10-28 03:07) [9]

> [7] markers ©   (28.10.06 03:03)

Невнимательный...я.


 
Gero ©   (2006-10-28 03:16) [10]

> [5] markers ©   (28.10.06 02:55)

Что значит «дописать строку»?


 
markers ©   (2006-10-28 03:20) [11]

УРА!!! Часть проблемы смог решить таким вот извращенским способом :)
procedure TMainForm.CatsViewCustomDrawItem(Sender: TCustomTreeView;
 Node: TTreeNode; State: TCustomDrawState; var DefaultDraw: Boolean);
var Rect:TRect;
   Rect2:TRect;
   inc:Integer;
   cattype:string;
begin
 if CatsView.Items.Count = 0 then Exit;
 with TTreeView(Sender).Canvas do
  begin
   DefaultDraw:=True;
   Rect:=Node.DisplayRect(False);
   Rect2:=Node.DisplayRect(True);
   if Node.Level > 0 then
    begin
     inc:=Node.Index+Node.Parent.Index;
    end
   else inc:=Node.Index-1;
   if odd(inc) then Brush.Color:=$FFFFFF
   else Brush.Color:=$F5F5F5;
   if (cdsSelected in State) or (cdsFocused in State) Then
    begin
     Brush.Color:=clNavy;
     Brush.Style:=bsSolid;
     Font.Color:=clWhite;
     Refresh;
     Font.Style:=[];
    end;
   FillRect(Rect);
   FillRect(Rect2);
   if Integer(Node.Data) > 0 then
    cattype:=GetCatStat(IntToStr(Integer(Node.Data)))
   else
    begin
     if Integer(Node.Data) = -1 then
      cattype:="New"
     else if Integer(Node.Data) = -2 then
      cattype:="Spec";
    end;
   if cattype <> "Normal" then
    begin
     Font.Style:=[fsItalic];
     if cattype = "New" then
      begin
       Font.Color:=clRed;
       TextOut (Rect2.Left+TextWidth(Node.Text)+7, Rect2.Top+1, "New!");
       Refresh;
       Font.Color:=clGray;
       TextOut(Rect2.Left+2,Rect2.Top+1,Node.Text);
      end
     else if cattype = "Spec" then
      begin
       Font.Color:=clGreen;
       TextOut (Rect2.Left+TextWidth(Node.Text)+7, Rect2.Top+1, "Сп!");
       Refresh;
       Font.Color:=clGray;
       TextOut(Rect2.Left+2,Rect2.Top+1,Node.Text);
      end;
    end;
  end;
end;


 
markers ©   (2006-10-28 03:37) [12]

Подскажите ещё плиз, как увеличить длинну итема не меняя его содержимое? Вообщем мне нужно добавить ещё пространство после пункта, когда был ListBox использовал:
 SendMessage(CategoryList.Handle, LB_SETHORIZONTALEXTENT, MaxLen+5, Longint(0));



Страницы: 1 вся ветка

Форум: "Начинающим";
Текущий архив: 2006.11.12;
Скачать: [xml.tar.bz2];

Наверх





Память: 0.49 MB
Время: 0.05 c
2-1161768977
Rule
2006-10-25 13:36
2006.11.12
AV при выполнении метода TObjectList.Sort


15-1161717019
XeRoN
2006-10-24 23:10
2006.11.12
Помогите плиз!


2-1162113417
Серый
2006-10-29 12:16
2006.11.12
Блокировка кнопки


2-1161810212
Aleks
2006-10-26 01:03
2006.11.12
Где запретить недопустимые символы в имени файла


15-1161867167
ReWQ
2006-10-26 16:52
2006.11.12
Помогите, пожалуйста!





Afrikaans Albanian Arabic Armenian Azerbaijani Basque Belarusian Bulgarian Catalan Chinese (Simplified) Chinese (Traditional) Croatian Czech Danish Dutch English Estonian Filipino Finnish French
Galician Georgian German Greek Haitian Creole Hebrew Hindi Hungarian Icelandic Indonesian Irish Italian Japanese Korean Latvian Lithuanian Macedonian Malay Maltese Norwegian
Persian Polish Portuguese Romanian Russian Serbian Slovak Slovenian Spanish Swahili Swedish Thai Turkish Ukrainian Urdu Vietnamese Welsh Yiddish Bengali Bosnian
Cebuano Esperanto Gujarati Hausa Hmong Igbo Javanese Kannada Khmer Lao Latin Maori Marathi Mongolian Nepali Punjabi Somali Tamil Telugu Yoruba
Zulu
Английский Французский Немецкий Итальянский Португальский Русский Испанский