我想通过DrawCell事件调用颜色对话框,通过鼠标点击列,弹出颜色对话框,该列显示选择color,同时在程序中调用选择的color.若是有其他好的办法也可以指点。谢谢!
达到目的就结贴给分!

解决方案 »

  1.   

    DELPHI不是有自带的颜色组件么?何必多此一举啊。有特别用途?
      

  2.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, ComCtrls, DB, ADODB, Grids;type
      TForm1 = class(TForm)
        Button1: TButton;
        StringGrid1: TStringGrid;
        ColorDialog1: TColorDialog;
        procedure StringGrid1Click(Sender: TObject);
        procedure StringGrid1SelectCell(Sender: TObject; ACol, ARow: Integer;
          var CanSelect: Boolean);
      private
        { Private declarations }
        currRow,currcol :integer;
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.StringGrid1Click(Sender: TObject);
    var
      i :integer;
      tempStr :string;
      StrHeight :integer;
      Rect: TRect;
    begin 
      if currRow=1 then
      begin
        if ColorDialog1.Execute then
        begin
          for i :=0 to StringGrid1.RowCount-1 do
          begin
            tempStr:=stringgrid1.Cells[currcol,i];
            Rect :=StringGrid1.CellRect(currcol,i);
            with stringgrid1.Canvas do
            begin
            StrHeight:=TextHeight(tempStr);
            Brush.Color:=ColorDialog1.Color  ;
            FillRect(Rect);
            Rectangle(Rect);
            TextOut(Rect.Left+2,Rect.Top+(Rect.Bottom-Rect.Top-StrHeight) div 2,tempStr);
            end;
          end;
        end;
      end;
    end;procedure TForm1.StringGrid1SelectCell(Sender: TObject; ACol,
      ARow: Integer; var CanSelect: Boolean);
    begin
      currRow := ARow;
      currcol :=ACol;
    end;end.