如何在stringgrid中打击文本(delphi)

 手机用户2502895261 发布于 2023-02-12 11:24

我想通过右键单击该行来触发stringgrid中一行中所有单元格的文本.我的代码是关于ok的,但是来自该行的单击单元格没有被攻击(另一个很好)!?!此外,我必须首先点击一行,然后右键单击继续,我想只是右键单击但不知道如何: - /我的代码:

procedure TForm1.StringGrid1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
  var
  i, j: integer;
begin
  if Button = mbRight then
  begin
    j:=StringGrid1.Selection.Top;
    If MessageDlg('Disable row '+IntToStr(j),
      mtConfirmation, [mbYes, mbNo], 0, mbYes) =mrYes then
    begin
      With Stringgrid1 As TStringGrid Do
        With Canvas Do
        begin
          for i := 0 to 2 do
          begin
            Rect := CellRect  (i, StringGrid1.Selection.Top);
            Font.Style := Font.Style + [fsStrikeOut];
            FillRect(Rect);
            DrawText(Canvas.Handle, PChar(Cells[i,j]), -1, Rect ,DT_CENTER );
          end;
        end;
    end;
  end;
end;

完美的事情!但是,如果我想存储受到攻击的状态,我还会添加一个包含'x'的列; 它工作正常但是 当我创建表单时我加载了stringrid值和第3列中的一些'x',我尝试在form.create中使用该代码来敲击这些行但是不起作用:-(

for J := 1 to stringGrid1.RowCount-1   do
begin
if  stringGrid1.Cells[3,J]='x' then
for I:=1 to 2 do
    begin
    StringGrid1.Canvas.Font.Style := Font.Style + [fsStrikeOut];
    StringGrid1.Canvas.Brush.Color := clBtnFace; // title
    StringGrid1.Canvas.FillRect(Rect);
    Rect.Top := Rect.Top + 4;
    drawText(Canvas.Handle, PChar(StringGrid1.Cells[I, J]), -1, Rect, DT_CENTER);
    StringGrid1.Invalidate;
    end
  else
    begin
    StringGrid1.Canvas.Font.Style := Font.Style - [fsStrikeOut];
    StringGrid1.Canvas.Brush.Color := clBtnFace; // title
    StringGrid1.Canvas.FillRect(Rect);
    Rect.Top := Rect.Top + 4;
    drawText(Canvas.Handle, PChar(StringGrid1.Cells[I, J]), -1, Rect, DT_CENTER);
    StringGrid1.Invalidate;
    end;
end;

任何的想法???

撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有