Search code examples
delphicomboboxdropdownmouse-cursor

How do I assure that mouse pointer appears when mouse moves over form after commanding the drop down for a combobox to show?


I have a problem where:

  1. I have a form with just a combobox.
  2. The combobox has focus and mouse is not hovering over the form when item 3 happens.
  3. I trigger the combobox's drop-down list to show on a key-press event.

When the drop-down list is visible and then I move my mouse pointer over the form, the pointer is either invisible, shows that it is busy, or shows the resizing icon but does not turn back to a normal pointer when over the form.

Is there something that can be done to assure that, when the drop-down of the combobox shows, that the mouse pointer is visible when I move the pointer over the form?

I have tried:

  • Applicaiton.ProcessMessages after showing the drop-down.
  • Changing focus to the form the combobox is on after showing the drop-down.
  • Adding Key := #0; after calling the drop-down to show.

    procedure TForm1.ComboBox1KeyPress(Sender: TObject; var Key: Char);
    begin
      SendMessage(ComboBox1.Handle, CB_SHOWDROPDOWN, Integer(True), 0);
      Key := #0;
    end;
    
  • Tried using a timer to trigger the drop-down within the key-press event.

  • Tried using "SetCursor" after commanding the drop-down to appear.
  • Tried using ".DroppedDown", but did not see any difference in result from that of "SendMessage".

I would hope to be able to show the mouse pointer after the drop-down is displayed, but it is hidden instead. Thanks for any suggestions.

(NOTE: This problem I have run into is not exlusive to Delphi. I was able to duplicate the issue using Visual C# 2017. Either way, if there is a way to correct this, it would be good to know).


Solution

  • As already commented to the question, the issue is not Delphi related. You can observe the same behavior in dialog boxes which contains a similar combo that the OS presents. One example is the one on the "run" dialog.

    Involving a single environment, re-setting the cursor in an OnDropDown event handler fixes the problem.

    procedure TForm1.ComboBox1DropDown(Sender: TObject);
    begin
      winapi.windows.SetCursor(Screen.Cursors[Cursor]);
    end;
    

    Originally I tested the above because no one calls SetCursor after the drop down. Though it seems that no one calls it before either. So I have no idea about the cause or why the above fix works.