terça-feira, 13 de março de 2012 13:06
I'm migrating my addin from VS2005 to VS2010, and find a regression blocking me. Here's demo VB.net code:
Dim cmdBarCtl 'As CommandBarControl
For Each cmdBarCtl In DTE.CommandBars("Code Window").Controls
Trace.WriteLine(cmdBarCtl.Caption & ", " & cmdBarCtl.Id)
In VS2005, it prints all captions and coresponding Id. But In VS2010, captions are correct, but Id of all controls are 0!
Does anyone know the reason? Or is it a VS2010 bug?
Todas as Respostas
terça-feira, 13 de março de 2012 17:23Moderador
It does appear that by default it will be 0 in 2010, though it was not guaranteed unique even pre-2010. What were you using it for exactly?
quarta-feira, 14 de março de 2012 00:20
Thanks for your reply. I need the Id to locate a VS button, then put my button after it, for example:
Dim contextPopupMenu As CommandBar = DTE.CommandBars("Code Window") Dim btnSetNextStmt As CommandBarControl = contextPopupMenu.FindControl(Id:=1813) ' Set Next Statement If Not btnSetNextStmt Is Nothing Then pos = btnSetNextStmt.Index + 1 myCmd.AddControl(contextPopupMenu, pos)
FindControl method can only find by Type, Id or Tag. Tag is empty for almost all standard VS buttons, and type is also useless. Maybe It works to scan all controls and compare the caption, but I don't think the caption is reliable. Do you have any ideas?
- Editado skyshore2001 quarta-feira, 14 de março de 2012 02:31 format
quarta-feira, 14 de março de 2012 00:35Moderador
Is the item you are looking for on the top level of the Code Window menu or nested? You can use the indexer of the controls collection with the string name (English name will work, even in localized builds) as long as the search doesn't require recursion into nested menus (the indexer does not recurse, only FindControl does that).
- Marcado como Resposta skyshore2001 quarta-feira, 14 de março de 2012 02:43
quarta-feira, 14 de março de 2012 02:25
Great! I tried it in macro window:
cmdBar As CommandBar = DTE.CommandBars("Code Window") Trace.WriteLine(cmdBar.Controls("Set N&ext Statement").Caption) Trace.WriteLine(cmdBar.Controls("Set Next Statement").Caption)
Both work! Now I use the one without "&" in my code. I wish it is available for other transalations.
Thank you Ryan!
- Editado skyshore2001 quarta-feira, 14 de março de 2012 02:29 format