用CheckListBox1控件,我想实现这种功能,当CheckListBox1控件里选中哪行数据,我想实现哪行数据就把字体改变颜色。快各位帮忙呀!!

解决方案 »

  1.   

    看看TCheckListBox的OnDrawItem的帮助,有一个例子,也许对你有帮助!!!
      

  2.   

    哈哈 就是这个吧!
    var
      FBmpGrayed, FBmpChecked, FBmpUnchecked: TBitmap;
    //...
    //Load bitmaps representing item states
    procedure TForm1.FormCreate(Sender: TObject);
    begin
      FBmpGrayed := TBitmap.Create;
      FBmpGrayed.LoadFromFile('grayed.bmp');
      FBmpChecked := TBitmap.Create;
      FBmpChecked.LoadFromFile('checked.bmp');
      FBmpUnchecked := TBitmap.Create;
      FBmpUnchecked.LoadFromFile('unchecked.bmp');end;
    ?
    //Destroy images when disposing of the form
    procedure TForm1.FormDestroy(Sender: TObject);
    begin
      FBmpGrayed.Free;
      FBmpChecked.Free;
      FBmpUnchecked.Free;
    end;
    ?
    //OnDrawItem event handler
    procedure TForm1.cxCheckListBox2DrawItem(Control: TWinControl;
      Index: Integer; Rect: TRect; State: TOwnerDrawState);
    var
      ACanvas: TcxCanvas;
      AText: string;  ATextRect: TRect;
      AGlyphWidth: Integer;
      AListBox: TcxCheckListBox;
      ACheckBmp: TBitmap;
      ACanvasFont: TFont;
      AItemState: TcxCheckBoxState;
      AItemEnabled: Boolean;
    begin
      AListBox := (Control as TcxCheckListBox);
      ACanvas := AListBox.InnerCheckListBox.Canvas;
      ACanvasFont := ACanvas.Font;
    ?
      AItemState := AListBox.Items[Index].State;
      AItemEnabled := AListBox.Items[Index].Enabled;
    ?
      case AItemState of
        cbsUnchecked:      begin
            ACheckBmp := FBmpUnchecked;
            ACanvasFont.Color := clBlack;
          end;
        cbsChecked:
          begin
            ACheckBmp := FBmpChecked;
            ACanvasFont.Style := [fsBold];
            ACanvasFont.Color := clBlack;
          end;
        cbsGrayed:
          begin
            ACheckBmp := FBmpGrayed;
            ACanvasFont.Color := clGray;
          end;
      end;
    ?
      ACanvas.Brush.Color := clWhite;
      ACanvas.FillRect(Rect);  AGlyphWidth := ACheckBmp.Width;
      ACanvas.DrawGlyph(Rect.Left, Rect.Top, ACheckBmp, AItemEnabled);
    ?
      AText := AListBox.Items[Index].Text;
      ATextRect := Rect;
      ATextRect.Left := ATextRect.Left + 3 + AGlyphWidth;
      ACanvas.DrawTexT(AText, ATextRect, 0);
    end;
      

  3.   

    呵呵 在vba里做过,在delphi里没做过,帮你up