在StringGrid中画图,我想在左键单击该图片时,显示一红色边框表示选中,右键单击清除该红色边框。。。(100分)

  • 主题发起人 还是朋友
  • 开始时间

还是朋友

Unregistered / Unconfirmed
GUEST, unregistred user!
在stringGrid中显示图片已经没有问题。

单击显示红色边框,与清除也已经没有问题,
但问题
1:为什么不能多选????
2:当 stringGrid中多行时,即使选中,可是上下拉动滚动条后,再拉回来,又变为 不选中。。。怎么办??
程序简单如下:

procedure TFrmReport.ImgListMouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
ImgList.MouseToCell(x, y, ACol, ARow);
if (Button = mbLeft) then begin
gMouseDown := true;
end;
if (Button = mbRight) then begin
RgMouseDown := true;
end;
end;

procedure TFrmReport.ImgListMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
Rect, NewRect: TRect;
begin
Rect := ImgList.CellRect(ACol, ARow);
NewRect.Left :=Rect.left + 1;
NewRect.Top :=Rect.top + 1;
NewRect.Right :=Rect.right - 1;
NewRect.Bottom :=Rect.Bottom - 1;
if (Button = mbLeft) then begin
if (ACol = 1) and (gMouseDown) then begin
DrawBorder(NewRect);
end;
gMouseDown := false;
end;
if (Button = mbRight) then begin
if (ACol = 1) and (RgMouseDown) then begin
ClearBorder(NewRect);
end;
RgMouseDown := false;
end;
end;

其中ACol, ARow为全局变量。
ImgList为TStringGrid。

哪位能帮帮忙。谢谢啦。
 
OnDrawCell ,自己维护状态
 
那还有其它什么好办法吗???
 
stringgrid会将不显示的部分在显示的时候进行重绘操作,所以,你想达到你的目的,除了
自绘操作,没有别的好办法。
 
已经解决。谢谢。
 
多人接受答案了。
 
顶部