2012-10-21 36 views
6

Tôi đang cố gắng cải thiện GUI bằng cách giảm số lượng nhấp chuột cần thiết để thực hiện một số hành động. Tuy nhiên, một thành phần VCL gây phiền toái cho tôi là một TValueListEditor chứa một danh sách các khóa và giá trị, tất cả được điều khiển bởi các trình đơn thả xuống. Chọn một tùy chọn luôn đòi hỏi ba lần nhấp chuột, khi chỉ có hai là cần thiết:Luôn hiển thị các tùy chọn thả xuống trong TValueListEditor

Bad

Tại thời điểm này trong thời gian, dòng trên cùng có trọng tâm, và giá trị có thể được thay đổi bằng cách sử dụng menu thả xuống (hai lần nhấp chuột). Tuy nhiên, khi người dùng muốn chỉnh sửa một khóa khác, trước tiên anh ta phải thay đổi tiêu điểm thành khóa đó trước khi có thể sử dụng trình đơn thả xuống (ba lần nhấp).

Có cách nào để hiển thị mũi tên thả xuống trên tất cả các hàng để ngăn chặn nhấp chuột bổ sung đó không?

Dưới đây là một ví dụ mockup của những gì tôi muốn đạt được:

Good

+1

có thể tốt hơn giải pháp sẽ được thiết lập hàng tập trung vào sự kiện onMouseMove? – teran

Trả lời

8
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

+0

Điều đó dường như hoạt động hoàn toàn tốt. Một bên lưu ý mặc dù (một số chi tiết tôi quên đề cập đến): Tôi sử dụng Delphi 7 và nó tuyên bố các dịch vụ chủ đề như 'ThemeServices' thay vì 'StyleServices', nó không lộ DrawCellHighlight và nó xác định mũi tên thả xuống như 'tcDropDownButtonNormal' nhưng ngoài từ đó, đây là một giải pháp tuyệt vời. – Orwell

+0

Tôi có thể đề xuất cải tiến không? Ít nhất trong Delphi 7, khi thành phần này được thêm vào bảng màu và được sử dụng để thiết kế biểu mẫu, EditList có thể không phải lúc nào cũng được chỉ định, dẫn đến khá nhiều lỗi bị lỗi. Tôi đề nghị thêm kiểm tra cho 'Đã gán (EditList)' cho bất kỳ nơi nào sử dụng nó. – Orwell

+0

@Orwell Tôi không thiết kế và cũng không thử nghiệm nó để được cài đặt như một thành phần. Nhưng bạn có thể/có thể tự thay đổi nó ở đây. Có lẽ thêm một tài sản tương ứng quá sau đó? – NGLN

Các vấn đề liên quan