哪图,标题本是单价和数量,着色是为了提示操作者这两条可以修改,但着色把标题也着没了,怎么办 代码如下 begin if (ACol=7) or (ACol=8) then begin StringGrid1.Canvas.Brush.color:=clcream; StringGrid1.Canvas.FillRect(Rect); end;
给你修改了一下,再试试? if ((ACol=7) or (ACol=8))and (arow>0) then begin StringGrid1.Canvas.Brush.color:=clcream; StringGrid1.Canvas.FillRect(Rect); end;
hys_427 谢谢你!可以是可以,但是我输入的单价和数量被颜色盖住了,没办法显示出来,还有办法吗
if ((ACol=7) or (ACol=8))and (arow >0) then begin StringGrid1.Canvas.Brush.color:=clcream; StringGrid1.Canvas.FillRect(Rect); stringGrid1.canvas.TextOut(Rect.left+2,Rect.Top+2,stringgrid1.canvas.cells[ACol,ARow]); end;
不好意思,搞错了 if ((ACol=7) or (ACol=8))and (arow >0) then begin StringGrid1.Canvas.Brush.color:=clcream; StringGrid1.Canvas.FillRect(Rect); stringGrid1.canvas.TextOut(Rect.left+2,Rect.Top+2,stringgrid1.cells[ACol,ARow]); end;
procedure TF_jhd.StringGrid1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); var ACol,ARow:Integer; begin StringGrid1.MouseToCell(X,Y,ACol,ARow); //arow:=(IntToStr(ARow)); 加这句有错,类型不匹配 StringGrid1.Canvas.Brush.color:=clcream; StringGrid1.Canvas.FillRect(Rect); stringGrid1.canvas.TextOut(Rect.left,Rect.Top,stringgrid1.cells[ACol,ARow]); end; 另外,看在你认定我了的份上,再给你一个好东西,先把stringgrid的背景色改一下,然后试试下面的效果 procedure TForm1.StringGrid1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); var rect1,rect:TREct; defaultPenColor:Tcolor; defaultPenwidth:integer; acol,arow:integer; begin with self.StringGrid1 do begin MouseToCell(x,y,acol,arow); rect:=CellRect(acol,arow); if (acol>0) and (arow>0) then begin rect1.Left:=rect.Left+1; rect1.top:=rect.Top+1; rect1.Right:=rect.Right-1; rect1.Bottom:=rect.Bottom-1; defaultpencolor:=Canvas.Pen.Color; defaultPenwidth:=Canvas.Pen.Width; Canvas.Pen.Color:=clwhite; Canvas.MoveTo(rect1.Left,rect1.Bottom); Canvas.LineTo(rect1.Left,rect1.Top); Canvas.LineTo(rect1.Right,rect1.Top); Canvas.Pen.Color:=defaultpencolor; Canvas.LineTo(rect1.Right,rect1.Bottom); Canvas.LineTo(rect1.Left,rect1.Bottom); sleep(50); self.StringGrid1.Canvas.Pen.Width:=defaultpenwidth; self.StringGrid1.Canvas.FillRect(rect); end; end; end;
MouseDown还是出错了呀,提示 [Error] Fjhd.pas(420): There is no overloaded version of 'Rect' that can be called with these argument 真的好感谢你,太有诚意了,会记住你的 我就想把stringgrid做漂亮些,嘿嘿,非常有兴趣!QQ 525068254交个朋友!
//这个方法应该更适合你的 procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState); begin with self.StringGrid1 do if (ARow=Row)and(ACol=col) then begin Canvas.Brush.Color:=clRed; Canvas.FillRect(Rect); Canvas.TextOut(Rect.left+2,Rect.top+2,Cells[acol,arow]); end; end;
if ((ACol=7) or (ACol=8))and (arow>0) then
begin
StringGrid1.Canvas.Brush.color:=clcream;
StringGrid1.Canvas.FillRect(Rect);
end;
begin
StringGrid1.Canvas.Brush.color:=clcream;
StringGrid1.Canvas.FillRect(Rect);
stringGrid1.canvas.TextOut(Rect.left+2,Rect.Top+2,stringgrid1.canvas.cells[ACol,ARow]);
end;
怎么定义呀,最后麻烦你一次呀
进货时点击左边按钮从其它界面将货物数据导入,只需输入单价和金额
if ((ACol=7) or (ACol=8))and (arow >0) then
begin
StringGrid1.Canvas.Brush.color:=clcream;
StringGrid1.Canvas.FillRect(Rect);
stringGrid1.canvas.TextOut(Rect.left+2,Rect.Top+2,stringgrid1.cells[ACol,ARow]);
end;
procedure TF_jhd.StringGrid1MouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);var
ACol,ARow:Integer;
begin
StringGrid1.MouseToCell(X,Y,ACol,ARow);
arow:=(IntToStr(ARow));
StringGrid1.Canvas.Brush.color:=clcream;
StringGrid1.Canvas.FillRect(Rect);
stringGrid1.canvas.TextOut(Rect.left,Rect.Top,stringgrid1.cells[ACol,ARow]);
end;
我想实现鼠标点哪一条,哪一条变色,哪有错呀,哈哈,认定你了,再次感谢
Button: TMouseButton; Shift: TShiftState; X, Y: Integer); var
ACol,ARow:Integer;
begin
StringGrid1.MouseToCell(X,Y,ACol,ARow);
//arow:=(IntToStr(ARow)); 加这句有错,类型不匹配
StringGrid1.Canvas.Brush.color:=clcream;
StringGrid1.Canvas.FillRect(Rect);
stringGrid1.canvas.TextOut(Rect.left,Rect.Top,stringgrid1.cells[ACol,ARow]);
end; 另外,看在你认定我了的份上,再给你一个好东西,先把stringgrid的背景色改一下,然后试试下面的效果
procedure TForm1.StringGrid1MouseMove(Sender: TObject; Shift: TShiftState;
X, Y: Integer);
var
rect1,rect:TREct;
defaultPenColor:Tcolor;
defaultPenwidth:integer;
acol,arow:integer;
begin
with self.StringGrid1 do
begin
MouseToCell(x,y,acol,arow);
rect:=CellRect(acol,arow);
if (acol>0) and (arow>0) then
begin
rect1.Left:=rect.Left+1;
rect1.top:=rect.Top+1;
rect1.Right:=rect.Right-1;
rect1.Bottom:=rect.Bottom-1;
defaultpencolor:=Canvas.Pen.Color;
defaultPenwidth:=Canvas.Pen.Width;
Canvas.Pen.Color:=clwhite;
Canvas.MoveTo(rect1.Left,rect1.Bottom);
Canvas.LineTo(rect1.Left,rect1.Top);
Canvas.LineTo(rect1.Right,rect1.Top);
Canvas.Pen.Color:=defaultpencolor;
Canvas.LineTo(rect1.Right,rect1.Bottom);
Canvas.LineTo(rect1.Left,rect1.Bottom);
sleep(50);
self.StringGrid1.Canvas.Pen.Width:=defaultpenwidth;
self.StringGrid1.Canvas.FillRect(rect);
end;
end;
end;
MouseDown还是出错了呀,提示
[Error] Fjhd.pas(420): There is no overloaded version of 'Rect' that can be called with these argument
真的好感谢你,太有诚意了,会记住你的
我就想把stringgrid做漂亮些,嘿嘿,非常有兴趣!QQ 525068254交个朋友!
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
ACol,ARow:Integer;
rect:TRect; //加个类型声明
begin
StringGrid1.MouseToCell(X,Y,ACol,ARow);
//arow:=(IntToStr(ARow)); 加这句有错,类型不匹配
rect:=stringgrid1.CellRect(acol,arow); //再加上这句,试试
StringGrid1.Canvas.Brush.color:=clblue;
StringGrid1.Canvas.FillRect(Rect);
stringGrid1.canvas.TextOut(Rect.left,Rect.Top,stringgrid1.cells[ACol,ARow]);
end;
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
begin
with self.StringGrid1 do
if (ARow=Row)and(ACol=col) then
begin
Canvas.Brush.Color:=clRed;
Canvas.FillRect(Rect);
Canvas.TextOut(Rect.left+2,Rect.top+2,Cells[acol,arow]);
end;
end;