views:

87

answers:

1

I have a combobox in a Word addin. The contents of the combobox are often long enough to drape over Word's Zoom slider-bar control. However, selecting an item directly over the zoom control (which is hidden from view) causes the zoom control to get focus, close the combobox, and change your zoom setting! The selection in the combobox is untouched.

How can I make the combo box keep focus and change the selected value to the item (over the zoom bar) selected? Thanks...

A: 

I've run into this same issue with WPF, and it looks like it has something to do with the way Word is handling events from child windows. Whenever the dropdown list (or probably any other "popup" control like a context menu) is drawn over one of Word's windows, it gets a bit greedy and assumes you're clicking on the underlying window.

I don't know a whole lot about how messaging/events works in Windows and I haven't had time to figure out the best way to address the problem, but based on a post somewhere about creating borderless windows I tried modifying the window styles of the WinForms user control as follows (windows style constants from http://www.pinvoke.net/default.aspx/Constants/Window%20styles.html):

    protected override CreateParams CreateParams
    {
        get
        {
            CreateParams p = base.CreateParams;
            if (!DesignMode)
            {
                unchecked
                {
                    p.Style = (int)(WindowStyles.WS_VISIBLE |
                                    WindowStyles.WS_POPUP |
                                    WindowStyles.WS_CLIPSIBLINGS |
                                    WindowStyles.WS_CLIPCHILDREN);
                }
            }
            return p;
        }
    } 

Curiously (or maybe not so curiously for people that are more familiar with Windows messages), the dropdown DOES respond to keyboard events (e.g. click to pop up the list, then use the keyboard to select an item).

Functionally there doesn't seem to be a problem with the above code...but I'm not sure what the ramifications are of saying the user control is a popup instead of a child.

Another post that relates to this is http://stackoverflow.com/questions/183035/wpf-combobox-doesnt-stay-open-when-used-in-a-task-pane.

Paul K