Secondary Form Takes Focus Away From Main Form RRS feed

  • Question

  • I'm working on a ribbon form - a duplicate of the Office 2010 (and, later, a duplicate of the office 2007) interface. I have a form that pinvokes DWM methods to extend the aero glass down the right distance. I have the file menu button and the ability to make ribbon tabs on the ribbon form. The ribbon tabs showed right, so I started working on being able to minimize the ribbon. In order to be able to get the minimized ribbon tab to fade when you click off of it, the ribbon tab container is moved to another customized form control (borderstyle=none) that automatically loses opacity when neither it nor any of it's child controls has focus.

    Here is a picture of Office 2010 minimized ribbon tab fading when you click off of it:

    This is the effect I am trying to achieve. I have it working perfectly, except for one thing...

    The only problem I am having with it is that when the minimized ribbon tab form has focus, (I have it set to fade if it doesn't contain focus,) the main form doesn't have focus and appears to be in the background, like any window does when it is onscreen but it doesn't have focus. What I'm trying to do: I'm trying to make it so that if anything on the main form, or anything on the minimized ribbon tabs form, is selected, then the main form *appears* selected - it doesn't necessarily need to be - but if anything on the main form is selected that is not on the minimized ribbon tab form, then the minimized ribbon tab form fades.

    One example that comes to mind is a context menu - (I think that a context menu is a form - at least, it's definitely not an embedded control). Here's a picture that shows a context menu extruding from a top-level window (MS Word) without taking the focus away from MS word -

    I program in VB.NET using Windows Forms, but I would be glad for instructions or pointers in any of the .NET languages.

    If anybody can help me, this is a problem I have worked over long and hard, and I don't know where to turn. Thanks in advance,



    Oh - and, before you move this question (yes, I know it's kind of off-topic) know that I was told to post here by a moderator. Proof

    Thanks for your help!
    Monday, March 14, 2011 8:57 PM

All replies

  • Hello Brandon,

    Thank for posting. If I understand you correctly, what you are using Ribbon in Windows form application like one in Office application. Right? If yes, actually, this forum is mainly for Office development issue. As far as I see, you question is more a Window Ribbon development issue. So here, to get more support/responses, I recommend you could try to ask in Windows Ribbon Development forum, which seems to be a right forum for this issue.

    If you have any concern on this post, or I have mistaken this issue, just feel free to point me out. Have a nice day.

    Bessie Zhao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, March 16, 2011 9:51 AM
  • Thanks for responding.

    I should probably clear this up some more - I am not using the Windows Ribbon API at all to develop my ribbon application. Instead, I am using VB.NET to duplicate the Office ribbon exactly - Office 2010, to be exact, which I'm pretty sure is not supported by that API. I have a working, functional ribbon tab interface, but I am trying to fix this one problem.

    When the ribbon is minimized, then the ribbon tab is "hidden." (This is not the problem I just talked about.) If you click on one of the tabs, the ribbon tab is shown in a separate class (also inherited from so that (as you can read above) it fades away when it does not contain focus. This works all right - it fades away perfectly, and it is functional.

    But - because it is in a separate form (in order to support the "fade" functionality) it takes focus away from the main ribbon form. The ribbon tab container is set to the foreground window, which effects the appearance of the main form, but only until the ribbon tab "container" form fades away and loses focus.

    I cannot solve this problem by keeping the focus in the main ribbon form, because there will later be controls that need to have focus in order to function correctly in the ribbon tabs.

    I tried to overload the ContainsFocus property on the main ribbon form, but that doesn't fool the actual windows API.

    Sorry I didn't make that clear enough.

    PS. I did try posting in that forum, and somebody told me that that's the wrong spot to post, and that I should post it again here - I know that what I'm trying to do has nothing to do with office development. Here is a link to it -

    Thanks for your help!
    Thursday, March 17, 2011 3:13 PM