delphi的stringgrid的drawcell事件的两个功能怎么协调?

procedureTForm1.StringGrid1DrawCell(Sender:TObject;ACol,ARow:Integer;Rect:TRect;State... procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
begin
{ if not((acol=icol)and(arow>=stringgrid1.FixedRows))then //重画列颜色
exit;
with stringgrid1 do
begin
Canvas.Brush.Color:=mycolor;
Canvas.FillRect(rect);
Canvas.TextOut(rect.Left+2,rect.Top+2,stringgrid1.Cells[acol,arow]);
end; }

if not((arow=irow)and(acol>=stringgrid1.FixedCols))then //重画行颜色
exit;
with stringgrid1 do
begin
Canvas.Brush.Color:=mycolor;
Canvas.FillRect(rect);
Canvas.TextOut(rect.Left+2,rect.Top+2,stringgrid1.Cells[acol,arow]);
end;
end;
展开
 我来答
cb120520025
推荐于2016-04-13 · TA获得超过347个赞
知道小有建树答主
回答量:323
采纳率:0%
帮助的人:571万
展开全部
var
Form1: TForm1;
icol:integer;
irow:integer;//添加这个行序号变量
mycolor:TColor;
implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
var
i,j:integer;
begin
icol := -1;
mycolor := clwhite;
with stringgrid1 do
for i:=1 to colcount-1 do
for j:=1 to rowcount-1 do
begin
cells[i,0]:='第'+inttostr(i)+'列';
cells[0,j]:='第'+inttostr(j)+'行';
end;
end;

procedure TForm1.N2Click(Sender: TObject);
begin
icol:=stringgrid1.Col ;
mycolor:=clred;
irow := -1;//用于在drawcell中判断是画行还是画列
stringgrid1.Repaint ;
end;

procedure TForm1.N3Click(Sender: TObject);
begin
icol:=stringgrid1.Col ;
mycolor:=clblue;
irow := -1;//用于在drawcell中判断是画行还是画列
stringgrid1.Repaint ;
end;

procedure TForm1.StringGrid1MouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
if button=mbright then
begin
mouse_event(mouseeventf_leftdown,x,y,0,0);
mouse_event(mouseeventf_leftup,x,y,0,0);
end;
end;

{ 添加指定行颜色的菜单}
procedure TForm1.N5Click(Sender: TObject);
begin
irow:=stringgrid1.row ;
mycolor:=clyellow;
icol := -1;//用于在drawcell中判断是画行还是画列
stringgrid1.Repaint ;
end;

procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
begin
if icol <> -1 then
begin
if not((acol=icol) and (arow>=stringgrid1.FixedRows))then
exit;
end
else if irow <> -1 then
begin
if not((arow=irow) and (arow>=stringgrid1.FixedCols))then
exit;
end;
with stringgrid1 do
begin
Canvas.Brush.Color:=mycolor;
Canvas.FillRect(rect);
Canvas.TextOut(rect.Left+2,rect.Top+2,stringgrid1.Cells[acol,arow]);
end;
end;
手机用户57830
2009-05-23 · 超过31用户采纳过TA的回答
知道答主
回答量:78
采纳率:0%
帮助的人:0
展开全部
你是不是要画十字,
procedure TForm1.StringGrid1DrawCell(Sender:TObject;ACol,ARow:Integer;
Rect:TRect;State:TGridDrawState);
begin
if (acol=icol)and(arow>=stringgrid1.FixedRows) then //重画列颜色
with stringgrid1 do
begin
Canvas.Brush.Color:=clBlue;
Canvas.FillRect(rect);
Canvas.TextOut(rect.Left+2,rect.Top+2,stringgrid1.Cells[acol,arow]);
end;
if (arow=irow)and(acol>=stringgrid1.FixedCols) then //重画行颜色
with stringgrid1 do
begin
Canvas.Brush.Color:=clBlue;
Canvas.FillRect(rect);
Canvas.TextOut(rect.Left+2,rect.Top+2,stringgrid1.Cells[acol,arow]);
end;
end;
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式