加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

delphi – 始终在TValueListEditor中显示选项下拉列表

发布时间:2020-12-15 04:07:50 所属栏目:大数据 来源:网络整理
导读:我正在尝试通过减少执行某些操作所需的点击次数来改进GUI.但是,困扰我的一个VCL组件是TValueListEditor,它包含一个键和值列表,所有这些都由下拉列表控制.选择选项始终需要三次点击,只需要两次: 此时,最上面的行具有焦点,可以使用下拉列表(两次单击)更改值.
我正在尝试通过减少执行某些操作所需的点击次数来改进GUI.但是,困扰我的一个VCL组件是TValueListEditor,它包含一个键和值列表,所有这些都由下拉列表控制.选择选项始终需要三次点击,只需要两次:

此时,最上面的行具有焦点,可以使用下拉列表(两次单击)更改值.但是,当用户想要编辑不同的密钥时,他首先必须将焦点更改为该密钥才能使用下拉列表(三次单击).

有没有办法在所有行上显示下拉箭头以防止额外的点击?

这是我想要实现的模型示例:

解决方法

uses
  Vcl.Themes;

type
  TValueListEditor = class(Vcl.ValEdit.TValueListEditor)
  private
    procedure DrawDropDownButton(ACol,ARow: Integer; ARect: TRect;
      AState: TGridDrawState);
    function MouSEOverButton(X: Integer): Boolean;
  protected
    procedure DrawCell(ACol,ARow: Integer; ARect: TRect;
      AState: TGridDrawState); override;
    procedure DrawCellHighlight(const ARect: TRect; AState: TGridDrawState;
      ACol,ARow: Integer); override;
    procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X,Y: Integer); override;
  end;

{ TValueListEditor }

type
  TInplaceEditListAccess = class(Vcl.Grids.TInplaceEditList);

procedure TValueListEditor.DrawCell(ACol,ARow: Integer; ARect: TRect;
  AState: TGridDrawState);
begin
  inherited DrawCell(ACol,ARow,ARect,AState);
  DrawDropDownButton(ACol,AState);
end;

procedure TValueListEditor.DrawCellHighlight(const ARect: TRect;
  AState: TGridDrawState; ACol,ARow: Integer);
var
  R: TRect;
begin
  R := ARect;
  if ItemProps[ARow - FixedRows].HasPickList then
    Dec(R.Right,EditList.ButtonWidth);
  inherited DrawCellHighLight(R,AState,ACol,ARow);
  DrawDropDownButton(ACol,AState);
end;

procedure TValueListEditor.DrawDropDownButton(ACol,ARow: Integer;
  ARect: TRect; AState: TGridDrawState);
var
  Details: TThemedElementDetails;
begin
  if (ACol = 1) and (ARow >= FixedRows) and not (gdFocused in AState) and
    ItemProps[ARow - FixedRows].HasPickList then
  begin
    ARect.Left := ARect.Right - EditList.ButtonWidth;
    Details := StyleServices.GetElementDetails(tgDropDownButtonNormal);
    StyleServices.DrawElement(Canvas.Handle,Details,ARect);
  end;
end;

procedure TValueListEditor.MouseDown(Button: TMouseButton; Shift: TShiftState;
  X,Y: Integer);
var
  ACol: Integer;
  ARow: Integer;
begin
  inherited MouseDown(Button,Shift,X,Y);
  MouseToCell(X,Y,ARow);
  if (Button = mbLeft) and (ARow > FixedRows) and
    ItemProps[ARow - FixedRows].HasPickList and
    not EditList.ListVisible and MouSEOverButton(X) then
  begin
    EditorMode := True;
    TInplaceEditListAccess(EditList).DropDown;
  end;
end;

function TValueListEditor.MouSEOverButton(X: Integer): Boolean;
begin
  Result := (UseRightToLeftAlignment and (X < EditList.ButtonWidth)) or
    (not UseRightToLeftAlignment and (X > ClientWidth - EditList.ButtonWidth));
end;

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读