如何在网格单元中插入按钮? [英] how can I insert a button in grid cell?

查看:70
本文介绍了如何在网格单元中插入按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果您希望单元格显示按钮,则以下内容可在Delphi XE5中工作.但是,在Delphi XE6中却没有.

The following works in Delphi XE5 if you want a cell to display a button. However, in Delphi XE6 it doesn't.

Type
    TSimpleLinkCell = class(TTextCell)
    protected
        FButton: TSpeedButton;
        procedure ButtonClick(Sender: TObject);
    public
        constructor Create(AOwner: TComponent); reintroduce;
    end;

constructor TSimpleLinkCell.Create(AOwner: TComponent);
begin
    inherited Create(AOwner);
    Self.TextAlign := TTextAlign.taLeading;
    FButton := TSpeedButton.Create(Self);
    FButton.Parent := Self;
    FButton.Height := 16;
    FButton.Width := 16;
    FButton.Align := TAlignLayout.alRight;
    FButton.OnClick := ButtonClick;
end;

我如何在Delphi XE6中使以上工作正常?

How can i make the above work in Delphi XE6?

推荐答案

  1. 您的SpeedButton没有文本,因此在您使用鼠标进入该按钮之前,不会显示任何内容
  2. 如果您将TColumn类型插入此对象到网格中,它将起作用.这是您的代码的完整工作示例(已在XE4上测试):

  1. Your SpeedButton has no text so nothing will be displayed until you went into the button with the mouse
  2. If you make TColumn type which inserted this object into the grid, it will work. Here is fully working example of your code (tested on XE4):

unit Unit5;

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Rtti, System.Classes,
  System.Variants, FMX.Types, FMX.Controls, FMX.Forms, FMX.Dialogs,
  FMX.StdCtrls, FMX.Layouts, FMX.Grid;

type
  TSimpleLinkCell = class(TTextCell)
  protected
      FButton: TSpeedButton;
      procedure ButtonClick(Sender: TObject);
   public
      constructor Create(AOwner: TComponent); reintroduce;
  end;

  TButtonColumn=class(TColumn)
  protected
    function CreateCellControl: TStyledControl;override;
  end;

  TForm5 = class(TForm)
    Grid1: TGrid;
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form5: TForm5;

implementation
{$R *.fmx}

constructor TSimpleLinkCell.Create(AOwner: TComponent);
begin
    inherited Create(AOwner);
    Self.TextAlign := TTextAlign.taLeading;
    FButton := TSpeedButton.Create(Self);
    FButton.Parent := Self;
    FButton.Height := 16;
    FButton.Width := 16;
    FButton.Align := TAlignLayout.alRight;
    FButton.OnClick := ButtonClick;
//    FButton.Text:='Button';
end;

procedure TSimpleLinkCell.ButtonClick(Sender: TObject);
begin
  ShowMessage('The button is clicked!');
end;

function TButtonColumn.CreateCellControl: TStyledControl;
var
  cell:TSimpleLinkCell;
begin
  cell:=TSimpleLinkCell.Create(Self);
  Result:=cell;
end;

procedure TForm5.FormCreate(Sender: TObject);
begin
  Grid1.AddObject(TButtonColumn.Create(Grid1));
end;

end.

这篇关于如何在网格单元中插入按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆