Browse Source

Merge branch 'dev-bgracontrols' of https://github.com/bgrabitmap/bgracontrols into dev-bgracontrols

lainz 6 years ago
parent
commit
d2b5f6f8d3
2 changed files with 23 additions and 20 deletions
  1. 2 1
      .gitignore
  2. 21 19
      bccombobox.pas

+ 2 - 1
.gitignore

@@ -14,4 +14,5 @@ debug
 *.compiled
 *Thumbs.db
 *.app/*
-*.dSYM
+*.dSYM
+test/test_bccombobox/test_bccombobox

+ 21 - 19
bccombobox.pas

@@ -53,27 +53,29 @@ procedure TBCComboBox.ButtonClick(Sender: TObject);
 var
   p: TPoint;
 begin
-  if Assigned(FForm) then
+  if FForm=nil then
   begin
-    FreeAndNil(FForm);
-    Exit;
+    FForm := TForm.Create(Self);
+    FForm.Visible := False;
+    FForm.ShowInTaskBar:= stNever;
+    FForm.FormStyle := fsStayOnTop;
+    FForm.BorderStyle := bsNone;
+    FForm.AutoSize := True;
+    p := ControlToScreen(Point(FButton.Left, FButton.Top + FButton.Height));
+    FForm.Left := p.X;
+    FForm.Top := p.Y;
+    FListBox.Parent := FForm;
   end;
 
-  p := ControlToScreen(Point(FButton.Left, FButton.Top + FButton.Height));
-
-  FForm := TForm.Create(Self);
-  FForm.Visible := False;
-  FForm.FormStyle := fsStayOnTop;
-  FForm.BorderStyle := bsNone;
-  FForm.AutoSize := True;
-  FForm.Left := p.X;
-  FForm.Top := p.Y;
-  FListBox.Parent := FForm;
-
-  if FListBox.CanSetFocus then
-    FListBox.SetFocus;
-  FForm.Constraints.MinWidth := FButton.Width;
-  FForm.Visible := True;
+  if FForm.Visible then
+    FForm.Visible := false
+  else
+  begin
+    FForm.Constraints.MinWidth := FButton.Width;
+    FForm.Visible := True;
+    if FListBox.CanSetFocus then
+      FListBox.SetFocus;
+  end;
 end;
 
 function TBCComboBox.GetItems: TStrings;
@@ -83,7 +85,7 @@ end;
 
 procedure TBCComboBox.ListBoxClick(Sender: TObject);
 begin
-  FreeAndNil(FForm);
+  FForm.Visible := false;
   FButton.Caption := FListBox.Items[FListBox.ItemIndex];
 end;