我在STRINGGRID的一些单元格上填充了颜色,然后用鼠标点击某个单元格选中它,可是这样的话选中的那个单元格的颜色就不见了,并且如果这时重新显示后再点击别的单元格,除了这个单元格的颜色消失,连带着上一次点击的单元格的颜色也会不见,就象是有记忆一样.如果移动滚动条,被覆盖的部分的颜色也会不见.
我在onDrawCell里添加重新显示的代码后,它就一直在哪里重画,速度变慢了,影响其他的操作.觉得不太可行.
这该如何使得不管怎么动,颜色都保持原来的不变?
我在onDrawCell里添加重新显示的代码后,它就一直在哪里重画,速度变慢了,影响其他的操作.觉得不太可行.
这该如何使得不管怎么动,颜色都保持原来的不变?
procedure TForm1.Button2Click(Sender: TObject); //先把图象放入STRINGGRID中显示
var
pointcolor1:COLORREF;
i,j:integer;
begin
j:=0;
while j<image1.Height do
begin
i:=0;
while i<image1.Width do
begin
pointcolor1:=image1.Canvas.Pixels[i,j];
if pointcolor1<>RGB(255,255,255) then
begin
stringgrid2.Canvas.Brush.Color:=pointcolor1;
stringGrid2.Canvas.FillRect(stringGrid2.cellrect(i,j));
end;
i:=i+1;
end;
j:=j+1;
end;procedure TForm1.StringGrid2MouseDown(Sender: TObject; //鼠标选起点,终点
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
ACol,ARow: Integer;begin
StringGrid2.MouseToCell(X,Y,ACol,ARow);
if mouseMark then
begin
edit1.Text:=inttostr(ACol); //起点坐标
edit2.Text:=inttostr(ARow); mouseMark:=false;
end
else
begin
edit3.Text:=inttostr(ACol); //终点坐标
edit4.Text:=inttostr(ARow); mouseMark:=true;
end;
end;