gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 14:59:36 24 4
gpt4 key购买 nike

我正在尝试通过减少执行某些操作所需的点击次数来改进 GUI。然而,令我困扰的一个 VCL 组件是 TValueListEditor,它包含一系列键和值,所有这些都由下拉菜单控制。选择选项始终需要单击三次,而实际上只需要单击两次:

Bad

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

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

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

Good

最佳答案

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, ARow, ARect, 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, ARow, ARect, 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, ACol, 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;

enter image description here

关于delphi - 始终在 TValueListEditor 中显示选项下拉列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12997108/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com