How to create a DropDownList/ContextMenu style window?

I need a popup window(no border) to input some text. But it should be something like the drop down list of a combobox which doesn't make the owner form inactive. Making it a child window does that but it will be clipped by the owner form, while drop down list won't be clipped.

I've tried changing the CreateParams to use different set of flags, but not successful. And I've been googling the whole afternoon...

I saw someone says not to make that popup window active by SW_SHOWNA, but if the window is not active, then it cannot receive keyboard input.

Does anybody know how DropDownList/ContextMenu achieve that



Answer this question

How to create a DropDownList/ContextMenu style window?

  • chris_sentman

    In that case you need to implement it the hard way. You need to create a Form without any chrome and without a parent/owner. Then in order to show the Form you need to use the 'SetWindowPos' Win32 call and use the 'SW_SHOWNA' flag. This will display the form at the top level at the screen position you specify and will not activate it.

    Now you need to get input to your window and because it does not have the focus you need to steal the input. To do this you need to create a message filter by adding the 'IMessageFilter' to your Form and inside the Form constructor all 'Application.AddMessageFilter(this)'.

    Then implement the 'PreFilterMessage' on your form and inside here you will get all windows messages for your application before they are dispatched to the appropriate window handler. Here you need to spot any keyboard messages and prevent them from being dispatched. Instead you need to create the same message and send it to your textbox on the Form.

    Of course, you also need to make the caret appear in your text box and ensure your window is dismissed when focus changes or when the user presses ESC.

    It is alot of work if you really want to go that route.

    Phil Wright
    http://www.componentfactory.com
    Free user interface controls for .NET2


  • Stigster

    Well, I'm already inches far from that approach. It's a solution but not as ideal as drop-down list and context menu's approach. I don't know how the drop-down list and context menu achieve that. I don't see they interfere with the application's message loop, but the messages are filtered and not sent to the owner window when they're visible. Does the system just do some tricks internally to heck out that
  • Baskaran9324

    No, as I said, I don't want it to be clipped by the parent window. I want it to act the same way as drop-down list and context menu.
  • JimBooth

    qrli,

    Here is an excellent example of how you can good old Dotnet Forms as popup windows.I am sure you will find it helpful and hopefully it should solve your problem.

    http://www.vbaccelerator.com/home/net/code/controls/Popup_Windows/Popup_Windows/article.asp

    I personally liked it very much


  • NuclearIntern

    You might want to set the pop-up window border to Tool* to prevent the form from showing in the ALT+TAB list.

  • Eng. A. Kilani

    Set the form.TopLevel property to FALSE. Add the form to the parent.Controls collection. Make sure to use BringtoFront to make the form visible. The only downside is that the dropform can only be drawn within the parent boundary.

    I'll leave you the task of calculating the coordinates of the form location.


  • gav135

    form method;
    Set as Topmost to TRUE
    Set ShowInTaskBar to FALSE
    Set the ControlBox to FALSE
    Set the BorderStyle to Toolbox(prevents it from showing in ALT-TAB list)
    Hide/Close the form on DeActivate event
    Use PointToScreen(btn.left, btn.height) to get the new Location of the form and assign it to the form.


    usercontrol method;
    Create a user control for the drop down
    When the drop down button is clicked, assign the usercontrol parent to the immediate form
    Use BringtoFront()
    Hide/Dispose the user control on LostFocus event
    Position the user control relative to the button.

  • Mario Moore

    I'm sorry I didn't make myself clear.

    The focus issue is about "active status". Either a modal or modeless form will make the parent form inactive (the title bar become gray) when the popup form is visible, however a context menu or drop-down list will not.

    A child window/UserControl can successfully preserve the active status of parent form, but it will be clipped by the bounding box of the parent window while dropdown list/context menu will not.

    So I wonder how the drop-down list and context menu achieve the above two features.

    Any ideas


  • Charl46436

    If you need it to be active and take the focus then all you need is a modeless Form that I assume will destroy itself when it loses focus. You can remove the chrome around a Form by setting the 'FormBorderStyle = None' at design time. You can also set the 'BackColor = SystemColor.Control' to get the correct background appearance.

    It will not have a drop shadow but then neither would the technique of using SW_SHOWNA.

    Phil Wright
    http://www.componentfactory.com
    Free user interface controls for .NET2


  • Ormed

  • How to create a DropDownList/ContextMenu style window?