Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

286
Visualizações
Add a tool button dynamically with Visual Studio extensions

I'm building a Visual Studio extension, which should add my tool button on a ToolBar or ToolStrip.

There are 2 cases:

  • first case, add my red button to the toolbar/toolstrip which was added by another extension (Visual Micro), see image 1.

  • second case, add my red button to the Properties toolbar/toolstrip of the Visual Studio UI, see image 2.

Image 1:

enter image description here

Image 2:

enter image description here

I tried to implement the second case, but without any positive results.

Here is the code:

EventHandler btnClick = new EventHandler(delegate (Object o, EventArgs a)
            {
                //snip
            });
System.Drawing.Image img = System.Drawing.Image.FromFile("W:\\...\\red_btn.png");

ToolStripButton btn = new ToolStripButton("My Button", img, btnClick, "RedButton");
            btn.Width = 32;
            btn.Height = 32;
            btn.Visible = true;
IntPtr hProperties = FindWindowEx(IntPtr.Zero, IntPtr.Zero, "WindowsForms10.Window.8.app.0.c940ee_r43_ad1", null) ;
ToolStrip toolStrip = (ToolStrip)ToolStrip.FromHandle(hProperties);

if (toolStrip != null)
{
  toolStrip.Items.Add(btn);
  toolStrip.Refresh();
  toolStrip.Visible = true;
}

When I execute the above code from my ToolWindow1Control init() method, nothing happens. What I tried was to find the handle of toolbar from Properties window and add my button to it. But that is not working.

I'm expecting to add the red button to the Properties window's toolbar. This button should execute some code related to the source file which is currently viewed. And this is the second case.

For the first case I don't have any idea how to find the handle of that toolbar to add my button.

Please help.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

There aren't any toolbar or toolstrip HWNDs in WPF windows. What you are trying to do is not possible. If you need to add any visuals to Visual Studio's GUI, use the public API. This isn't just better, it's the only way to do this.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda