Solved

CommandBarControl.delete() not working as expected

Posted on 2011-02-16
3
730 Views
Last Modified: 2012-05-11
Testing out the CommandBarControl.Delete() method on addin_shutdown in a Word add-in app.

I want to add a button during startup and then delete it during shutdown. Problem happens when I rerun the addin application, I do a check to see if the CommandBarButton control is there and it always is.

The delete(false) procedure seems to remove the commandbarbutton from the commandbars collection, but when I restart the add-in to debug it reappears.

It is not working like I think it should. Does anyone have any suggestions as to how to properly dispose of a commandbarcontrol forever? I thought giving the delete method a temporary parameter of false would do the trick but not so.

Thanks in advance,
Mel
Microsoft.Office.Core.CommandBar cellbar;

  private void ThisAddIn_Startup(object sender, System.EventArgs e)
  {
   cellbar = Application.CommandBars["Text"];
   Microsoft.Office.Core.CommandBarButton button = (Microsoft.Office.Core.CommandBarButton)cellbar.FindControl(Microsoft.Office.Core.MsoControlType.msoControlButton, 1, "MYRIGHTCLICKMENU", missing, missing);
   if (button == null)
   {
    // add the button     
    button = (Microsoft.Office.Core.CommandBarButton)cellbar.Controls.Add(Microsoft.Office.Core.MsoControlType.msoControlButton, 1, missing, missing, true);
    button.Caption = "My Right Click Menu Item";
    button.BeginGroup = true;
    button.Tag = "MYRIGHTCLICKMENU";
   }
  }

  private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
  {
   Microsoft.Office.Core.CommandBarButton button = (Microsoft.Office.Core.CommandBarButton)cellbar.FindControl(Microsoft.Office.Core.MsoControlType.msoControlButton, 1, "MYRIGHTCLICKMENU", missing, missing);
   object val = false;
   button.Delete(val);
  }

Open in new window

0
Comment
Question by:rotovibe
  • 2
3 Comments
 
LVL 11

Expert Comment

by:Sudhakar Pulivarthi
ID: 34923454
Hi,
Please check out the conversation which helps to ur requirement.
http://social.msdn.microsoft.com/Forums/en/vsx/thread/8fff7d90-7867-4608-a8b6-ba9362d91411
0
 
LVL 11

Expert Comment

by:Sudhakar Pulivarthi
ID: 34923459

Check this notes on how to perform the actions by Carlos J. Quintero:
http://www.mztools.com/articles/2005/mz2005003.aspx
0
 
LVL 4

Accepted Solution

by:
jmdion earned 500 total points
ID: 34926269
I gave a quick look at my code for an add-in I wrote 2 years ago. This is what I understand/remember.

When you remove the CommandBarButton form the collection, it is not removed from Normal.dot.  All you can do is check if the button is present and make it hidden.

If you want more control then you must create you own Application.CustomizationContext by creating your own MyAddInName.dot file (and add it to the Templates collection).  You can create it and delete it at Startup() and ShutDown() if you don't want to confuse the users. This file will never be used as a real template but you need it anyway because you can't create a CustomizationContext without a template.  This is also better because there is less chance of interference if other addins store their customizations in Normal.dot or if Normal.dot becomes corrupt.

Besides the reference on MSDN Library on CustomizationContext, you can google for explanations on this topic by "Cindy Meister" or "Jonathan West".



0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction This tutorial provides instructions on how to properly format your Word document using the inbuilt tools provided. The benefits of using these tools means your documents are more accessible and easily portable to other applications an…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video shows where to find templates, what they are used for, and how to create and save a custom template using Microsoft Word.
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question