在大多数情况下,放置在所选TListItem上的按钮不会获​​得点击

时间:2018-09-14 08:55:06

标签: delphi listbox firemonkey

我在Android应用程序中有一个Firemonkey TListBox,并且在OnPaint中,我在所选的TListBoxItem上放置了3个按钮。它们正在显示,并且都分配了OnClick事件。但是,单击它们时,通常不会触发此事件。很少有人点击按钮。

我想TListBox已经收到点击并将其声明为已处理。 否则有其他办法吗?我可以按自己的形式注册水龙头,并根据水龙头的位置确定必须按下了哪些按钮吗?那怎么办?

这是当前解决方案的代码,将TListBox客户端对齐到表单,并将TLayout中的按钮右对齐。

unit MainForm;

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes, 
  System.Variants, FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, 
  FMX.Dialogs, FMX.Layouts, FMX.ListBox, FMX.Controls.Presentation, 
  FMX.StdCtrls, FMX.Objects;

type
  TForm1 = class(TForm)
    lb_Files: TListBox;
    Layout1: TLayout;
    Image1: TImage;
    Image2: TImage;
    Button1: TButton;
    Button2: TButton;
    Rectangle1: TRectangle;
    Rectangle2: TRectangle;
    procedure FormCreate(Sender: TObject);
    procedure lb_FilesPaint(Sender: TObject; Canvas: TCanvas;
      const ARect: TRectF);
    procedure Button2Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
  public
  end;

var
  Form1: TForm1;

implementation

uses
  System.UIConsts;

{$R *.fmx}

procedure TForm1.Button1Click(Sender: TObject);
begin
  lb_Files.ListItems[lb_Files.ItemIndex].Text := 'Info';
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  lb_Files.ListItems[lb_Files.ItemIndex].Text := 'Test';
end;

procedure TForm1.FormCreate(Sender: TObject);
var
  i : Integer;
begin
  for i := 0 to 30 do
    lb_Files.Items.Add('File' + i.ToString +'.dat');
end;

procedure TForm1.lb_FilesPaint(Sender: TObject; Canvas: TCanvas;
  const ARect: TRectF);
begin
  if lb_Files.ItemIndex > -1 then
  begin
    Layout1.Parent  := lb_Files.ListItems[lb_Files.ItemIndex];
    Layout1.Align   := TAlignLayout.Right;
    Layout1.Visible := true;
  end;
end;

end.

以下是FMX内容:

object Form1: TForm1
  Left = 0
  Top = 0
  Caption = 'Form1'
  ClientHeight = 480
  ClientWidth = 640
  StyleBook = StyleBook1
  FormFactor.Width = 320
  FormFactor.Height = 480
  FormFactor.Devices = [Desktop]
  OnCreate = FormCreate
  DesignerMasterStyle = 3
  object lb_Files: TListBox
    Align = Client
    Enabled = False
    Size.Width = 640.000000000000000000
    Size.Height = 480.000000000000000000
    Size.PlatformDefault = False
    StyleLookup = 'listboxstyle'
    TabOrder = 0
    OnPaint = lb_FilesPaint
    DisableFocusEffect = True
    DefaultItemStyles.ItemStyle = 'listboxitemstyle'
    DefaultItemStyles.GroupHeaderStyle = ''
    DefaultItemStyles.GroupFooterStyle = ''
    Viewport.Width = 640.000000000000000000
    Viewport.Height = 480.000000000000000000
    object Layout1: TLayout
      Position.X = 384.000000000000000000
      Position.Y = 192.000000000000000000
      Size.Width = 153.000000000000000000
      Size.Height = 50.000000000000000000
      Size.PlatformDefault = False
      TabOrder = 0
      object Rectangle1: TRectangle
        Align = Right
        Fill.Color = claBlue
        HitTest = False
        Position.X = 53.000000000000000000
        Size.Width = 50.000000000000000000
        Size.Height = 50.000000000000000000
        Size.PlatformDefault = False
        Stroke.Kind = None
        OnClick = Button1Click
        object Button1: TButton
          Align = Client
          Size.Width = 50.000000000000000000
          Size.Height = 50.000000000000000000
          Size.PlatformDefault = False
          StyleLookup = 'buttonstyle'
          TabOrder = 0
          TintColor = claBlue
          OnClick = Button1Click
        end
      end
      object Rectangle2: TRectangle
        Align = Right
        Fill.Color = claGreen
        HitTest = False
        Position.X = 103.000000000000000000
        Size.Width = 50.000000000000000000
        Size.Height = 50.000000000000000000
        Size.PlatformDefault = False
        Stroke.Kind = None
        OnClick = Button2Click
        object Button2: TButton
          Align = Client
          Size.Width = 50.000000000000000000
          Size.Height = 50.000000000000000000
          Size.PlatformDefault = False
          StyleLookup = 'buttonstyle'
          TabOrder = 0
          TintColor = claGreen
          OnClick = Button2Click
        end
      end
    end
  end
end

0 个答案:

没有答案