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; 展开
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; 展开
展开全部
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;
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;
展开全部
你是不是要画十字,
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;
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;
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询