我用listbox显示数据,但是我要把我特殊字符的颜色改变成其他不同颜色,要怎么做啊??能举个列子吗?谢谢了

解决方案 »

  1.   

    在ListBox1DrawItem事件中处理你是要处理某个字符还是某个item
      

  2.   

    在ListBox1DrawItem事件中处理 我要处理items中的特殊字符,设置成不通的颜色
      

  3.   

    procedure TForm1.ComboBox1DrawItem(Control: TWinControl; Index: Integer;
      Rect: TRect; State: TOwnerDrawState);
    begin
      if  Pos('OK',(Control as TComboBox).Items[Index]) > 0 then
         (Control as TComboBox).Canvas.Font.Color := clRed
      else
         (Control as TComboBox).Canvas.Font.Color := clBlack;   (Control as TComboBox).Canvas.TextOut(Rect.Left,Rect.Top,(Control as TComboBox).Items[Index]);
    end;
      

  4.   


    procedure TForm1.ComboBox1DrawItem(Control: TWinControl; Index: Integer; 
      Rect: TRect; State: TOwnerDrawState); 
    begin
      with Control as TListbox do
      begin
        Canvas.FillRect(Rect);//填充以前画的内容
         Canvas.Font.Color := clRed ;
       //显示当前Item的文字
        Canvas.TextOut(0, Rect.Top,
          bsSkinListBox1.Items[Index]);//处理状态为激活或选中时的样子
        if (odFocused in State) and (odSelected in State) then
          Canvas.DrawFocusRect(Rect); // Canvas.ClipRect); //
      end;
    end;
      

  5.   

    忘记改了,bsSkinListBox1换成当前控件名
      

  6.   

    listbox的style属性设置为lbOwnerDrawVariableprocedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;
      Rect: TRect; State: TOwnerDrawState);
    var
      s:string;
      i:Integer;
    begin
      if Index=0 then
      begin
        self.ListBox1.Canvas.FillRect(Rect);
      self.ListBox1.Canvas.Font.Color:=clRed;
      self.ListBox1.Canvas.TextOut(rect.Left+1,rect.Top+1,'你好');
      i:=self.ListBox1.Canvas.TextWidth('你好');
      self.ListBox1.Canvas.Font.Color:=clblue;
      self.ListBox1.Canvas.TextOut(rect.Left+2+i,rect.Top+1,'我是×××');
      self.ListBox1.Canvas.DrawFocusRect(Rect);
      end;
    end;
      

  7.   

    procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;
      Rect: TRect; State: TOwnerDrawState);
    var
      s,s1,s2:string;
      i:Integer;
      left:Integer;
    begin
      left:=0;
      s:=self.ListBox1.Items.Strings[index];
      while s<>'' do
      begin
        i:=Pos('你好',s);
        if i=0 then
          s:=''
        else
        begin
          s1:=Copy(S,1,i-1);
          s:=Copy(s,i+length('你好'),Length(s)-i-length('你好')+1);
          self.ListBox1.Canvas.FillRect(Rect);
          self.ListBox1.Canvas.Font.Color:=clBlack;
          self.ListBox1.Canvas.TextOut(Left+1,Rect.Top+1,s1);
          i:=self.ListBox1.Canvas.TextWidth(s1);
          left:=left+i+1;
          self.ListBox1.Canvas.Font.Color:=clRed;
          self.ListBox1.Canvas.TextOut(Left+1,rect.Top+1,'你好');
          i:=self.ListBox1.Canvas.TextWidth('你好');
          left:=left+i+1;
          self.ListBox1.Canvas.Font.Color:=clBlack;
          self.ListBox1.Canvas.TextOut(Left+1,Rect.Top+1,s);
          self.ListBox1.Canvas.DrawFocusRect(Rect);
        end;
      end;
    end;
    这个可能更贴近你的要求