VCL에서는 TComboBox DropDown 후 다른 부분을 선택하면 마우스 클릭이벤트가 발생하지 않지만 FMX에서는 이벤트가 발생한다.
보통 DropDown 후 아이템을 선택하지 않고 다른 부분을 선택하는 것은 취소의 의미인데 다른게 동작하니 별로 마음에 들지 않는다.
해결 방법은 다음과 같다.
type
TForm1 = class(TForm)
ComboBox1: TComboBox;
ComboBox2: TComboBox;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Single); override;
end;
var
Form1: TForm1;
implementation
{$R *.fmx}
function IsPopup(Control: IControl): Boolean;
begin
Result := False;
if (Control <> nil) then
begin
if Control.GetObject is TComboBox then
Result := TComboBox(Control.GetObject).DroppedDown
else
Result := GetPopupCount > 0;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
ComboBox1.Items.Add('a');
ComboBox1.Items.Add('a');
ComboBox2.Items.Add('a');
ComboBox2.Items.Add('a');
end;
procedure TForm1.MouseDown(Button: TMouseButton; Shift: TShiftState; X,
Y: Single);
begin
if IsPopup(Focused) then
Focused := nil
else
inherited;
end;
|