Toostrip (Menustrip) dropdown items freeze Office UI application

46 Views Asked by At

I got a strange bug in a Com addin loaded in Office (Excel, Word or Powerpoint)

I'm using a toolstrip (or menustrip) with toolstripitems: buttons and dropdownbutton (or splitbutton) to display custom usercontrol (form's Options, Filters for a gridview...) When manipulating the dropdown, if the mouse go over the hosted (user)control and then over another toolstrip item included in the toolstrip, the Office UI application become frozen (1). This arrives immediatly (if the form is modeless) of after closing the form (for modal form)

NB : The problem do not arrive if the toolstrip :

  • contains only toolstripitem buttons
  • contains a single toolstripitem using a dropdown (ie no other toolstrip items included)
  • if the mouse go over the dropdown hosted (user)control and then leave the toolstrip without hovering another toolstripitems
  • on a classic windows form application developped using .Net 7.0

(1) Frozen behaviour:

  • In Powerpoint: the working space (slide) do not allow selecting shapes anymore, the ribbon may become disabled
  • In Excel: the working space (worksheet) do not allow selecting shapes anymore, cells may be selected but not filled with value, the ribbon may become disabled
  • In Word: the working space do not allow selecting shapes anymore NB : If you activate another application (browser, visual studio) and then go back to Office, the ribbon of your Office application may become enabled (allowing closing the app) - but if you click on the working space the ribbon will come back to disabled state ! NB : you may need to use the Windows Task manager dialog box (Ctl+Alt+Del) to terminate the application process...

How to reproduce the problem :

  • Create a new empty form :

  • Call the following code (in the Form_Load event for example)

  • Manipulate any dropdown buttons this way: Click on "C 2" to open the dropdown menu. Move the cursor on the "B" letter of the "checkBox" then from there move the cursor upper to "C 3" button (then the dropdown automatically close)

  • Close the form. Et voila !

     Private Sub CreateToolstripDropDownsItems() 
          'Create Toolstrip 
          'NB: if bUseMultiToolStrips= true (ie DropDownsItems are in different toolstrip) the UI remains stable 
          'If false the UI will freeze 
          Dim bUseMultiToolStrips = False 
          'Use a ToolStripDropDownMenu with margins or classic (no incidence) 
          Dim bUseDropDownItems = False 
          ' 
          Dim tsToolStrip As ToolStrip 
          'Add 5  
          For i = 1 To 5 
              If i = 1 OrElse bUseMultiToolStrips Then 
                  tsToolStrip = New ToolStrip 
                  Me.Controls.Add(tsToolStrip) 
                  tsToolStrip.Dock = DockStyle.Top 
              End If 
              'Add a native control but we could also use a usercontrol 
              Dim chkBox As New CheckBox() 
              chkBox.Text = $"CheckBox {i}" 
              Dim tsControlHost As New ToolStripControlHost(chkBox) 
              'Create a ToolStripDropDownButton 
              Dim tsDDownBtn = New ToolStripDropDownButton() 
              tsDDownBtn.Text = $"C {i}" 
              tsDDownBtn.DisplayStyle = ToolStripItemDisplayStyle.Text 
              'Définit le ToolStripDropDown avec le control dedans 
              If bUseDropDownItems Then 'use a ToolStripDropDownMenu with margins.. 
                  tsDDownBtn.DropDownItems.Add(tsControlHost) 
                  Dim tsDropDownMenu = DirectCast(tsDDownBtn.DropDown, ToolStripDropDownMenu) 
              Else 'use a classic ToolStripDropDown 
                  Dim tsDropDown As New ToolStripDropDown() 
                  tsDropDown.Items.Add(tsControlHost) 
                  tsDDownBtn.DropDown = tsDropDown 
              End If 
              'Add at End 
              tsToolStrip.Items.Add(tsDDownBtn) 
          Next 
    
      End Sub 
    

Questions :

  • Have you already met this issue in a classic winform application or elsewhere ?
  • Does anyone have an idea of the mecanisms involved and what the solution would be ?

Thanks for any reply Regards, Xavier

0

There are 0 best solutions below