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

前端之家收集整理的这篇文章主要介绍了delphi – 始终在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;
原文链接:https://www.f2er.com/delphi/239245.html

猜你在找的Delphi相关文章