dotnet / winforms

Windows Forms is a .NET UI framework for building Windows desktop applications.
MIT License
4.41k stars 982 forks source link

Toolstrip dropdown items freeze Office UI application #10056

Closed XavierNV closed 1 year ago

XavierNV commented 1 year ago

.NET version

This issue occurs within office com add ins and concerns the .net framework (4.8). It's quite annoying as it prevent usage of toolstrip in Office application (Excel, Powerpoint, Word) if we use dropdown items - which is the main reason/advantage of using this control...

Did it work in .NET Framework?

No

Did it work in any of the earlier releases of .NET Core or .NET 5+?

Not concerned : Office com addins canno't use .Net 5 + (only .Net Framework) (but the bug does not arrive on a "classic" windows form application - developped using .Net 7.0 )

Issue description

I'm using a toolstrip with toolstripitems: buttons and dropdownbuttons (or splitbutton) to display custom usercontrol (form's Options, Filters for a gridview...) When manipulating the toolstrip if you open a dropdown menu, then go with mouseto a sub menu items or an hosted (user)control and then leave the dropdown by entering another toolstrip item using the mouse, the Office UI application become frozen (1). This arrives immediatly (if the form is modeless) of after closing the form (for a modal form) (1) Frozen behaviour :

NB : The problem do not arrive if the toolstrip :

NB : If you activate another application (eg : 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 Office application process...

Steps to reproduce

How to reproduce the problem :

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 

See also the discussion on addin express forum : https://www.add-in-express.com/forum/read.php?FID=5&TID=16604

elachlan commented 1 year ago

@merriemcgaw this is a .net framework issue.

merriemcgaw commented 1 year ago

@Olina-Zhang can you move this to the internal AzDO and then close this issue?

@XavierNV thank you so much for filing this issue. As you may know .NET Framework is considered "done" and the bar for any fixes is extremely high. At present we are focused on security and accessibility primarily. I will be happy to investigate the broader impact of this issue and see if it is suitable for a .NET Framework servicing update, but as I mentioned the bar is quite high to clear.

XavierNV commented 1 year ago

I understand... Thanks for your answer @merriemcgaw...

Olina-Zhang commented 1 year ago

@XavierNV could you please provide a sample application? In order to I can use it to repro your issue in Visual Studio, then file an internal bug to track. Thanks!

Olina-Zhang commented 1 year ago

@XavierNV I have created a reproduce application now.

XavierNV commented 1 year ago

@Olina-Zhang : did you created a VSTO addin and a form with the code in my first message (or any toolstrip with dropdown items?). Not sure to understand if you still need a sample application from me ? I will not be able to give you a sample VSTO addin (i'm using addin express tool for Com addins creation)... But i can give you the code for the form - or i can suggest ADX team to give you a VSTO addin...

Olina-Zhang commented 1 year ago

@XavierNV Yes, I used that form_load event code in my created PowerPoint/word add-in application, with added a ribbon to show form, and click the MenuItem to open its dropdown, then close from. It leads to I cannot interact with slide in PowerPoint, cannot input something in word-- see following recording. Don't need a sample from your side now. PowerPoint_freeze

XavierNV commented 1 year ago

Ok thanks you so much for taking this issue into consideration : ). It may seems it's not a big issue but it prevent use of using a toolstrip with dropdown content to display any user control (eg: filter, option, colors choice..) .. Thanks again @Olina-Zhang , @merriemcgaw

Olina-Zhang commented 1 year ago

@merriemcgaw filed an internal AzDo bug: https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1902740 to track, closing this one now.