New to the subject, I need to add a single command bar with one button to "All" instances of an Inspector class object, (New Message, Folder Items, etc...) Any help or code snippet would be appreciated.
Thanks in advance,
Ron |<:^)
New to the subject, I need to add a single command bar with one button to "All" instances of an Inspector class object, (New Message, Folder Items, etc...) Any help or code snippet would be appreciated.
Thanks in advance,
Ron |<:^)
How can I add a CommandBarButton to "ALL" Inspectors in Outlook 2003?
Troy Neville
you can add the following code, to just return if there is a command bar already by that name, as the first two lines of new inspector event
for
(int i = 1; i<=inspector.CommandBars.Count; i++)if (inspector.CommandBars
I am sorry the CommandBars index of i is showing up as lightbulb.
Thank
Pallavi
madhatt30
Thanks again Pallavi,
Your solutions were precise and shed clartiy on my problems. I rather liked the lightbulb!
Ron |<:^)
using System;
using
System.Windows.Forms;using
Microsoft.VisualStudio.Tools.Applications.Runtime;using
Outlook = Microsoft.Office.Interop.Outlook;using
Office = Microsoft.Office.Core;namespace
Outlook_Test_04{
public partial class ThisApplication{
private
Office.CommandBar newBar;private
Office.CommandBarButton newButton;private
Outlook.Inspectors inspectors;private
void ThisApplication_Startup(object sender, System.EventArgs e){
inspectors =
this.Inspectors;inspectors.NewInspector +=
new Microsoft.Office.Interop.Outlook.InspectorsEvents_NewInspectorEventHandler(inspectors_NewInspector);}
private
void ThisApplication_Shutdown(object sender, System.EventArgs e){
}
private
void inspectors_NewInspector(Outlook.Inspector inspector){
for (int i = 1; i <= inspector.CommandBars.Count; i++) if (inspector.CommandBarsnewBar = inspector.CommandBars.Add(
"ReminderControlBar", Office.MsoBarPosition.msoBarTop, false, true);// Add a button
newButton = (Office.
CommandBarButton)newBar.Controls.Add(Office.
MsoControlType.msoControlButton, 1, missing, missing, true);newButton.Caption =
"REMINDER: Transmitting propietary data is subject to company policy and regulation. Click here for more information.";newButton.FaceId = 172;
newButton.Click+=
new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(newButton_Click);newBar.Visible =
true;}
private
void newButton_Click(Office.CommandBarButton Ctrl, ref bool CancelDefault){
MessageBox.Show("If you have any questions regarding proprietary information, please call (888) 888-8888");}
#region
VSTO generated code /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InternalStartup(){
this.Startup += new System.EventHandler(ThisApplication_Startup); this.Shutdown += new System.EventHandler(ThisApplication_Shutdown);}
#endregion
}
}
tala
You can add the commandbar with the button in the newinspector event.
For Example....
public
partial class ThisApplication{
private Office.CommandBar newBar; private Office.CommandBarButton newButton; private Outlook.Inspectors inspectors; private void ThisApplication_Startup(object sender, System.EventArgs e){
inspectors =
this.Inspectors;inspectors.NewInspector +=
new Microsoft.Office.Interop.Outlook.InspectorsEvents_NewInspectorEventHandler(inspectors_NewInspector);}
private void ThisApplication_Shutdown(object sender, System.EventArgs e){
}
private void inspectors_NewInspector(Outlook.Inspector inspector){
newBar = inspector.CommandBars.Add(
"NewBar", Office.MsoBarPosition.msoBarTop, false, true); // Add a buttonnewButton = (Office.
CommandBarButton)newBar.Controls.Add(Office.
MsoControlType.msoControlButton, 1, missing, missing, true);newButton.Caption =
"NewButton";newButton.FaceId = 172;
newButton.Click+=
new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(newButton_Click);newBar.Visible =
true;}
private void newButton_Click(Office.CommandBarButton Ctrl, ref bool CancelDefault){
MessageBox.Show("clicked");}
Thanks,Pallavi
goranV
Thankyou Pallavi!
The only problem I face is that each time an Inspector is called now another CommandButtonBar is added to the object. How can I remove the CommandButtonBar each time so that they do not accumulate
Ron |<:^)
Hong Ju Zhang
I have a related problem. I'm adding a CommandBarButton almost exactly the same way, but the issue is that if I have more than one Inspector open the click event doesn't fire. Whar am I doing wrong:
///
<summary> /// Event handler for the new inspector event. Happens when a new window is opened in Outlook /// </summary> /// <param name="Inspector">The inspector window <see cref="Inspector"/></param> void _inspectors_NewInspector(Inspector Inspector){
//check active window to see if it's a mail item window if (Inspector.CurrentItem is MailItem){
//instatiate the mail item from current window_item = (
MailItem)Inspector.CurrentItem; if (!_item.Sent){
bool exists = false; //loop through commandbar collection to find Armada custom foreach (CommandBar cmd in Inspector.CommandBars){
if (cmd.Name == "Armada"){
exists =
true;}
}
if (!exists){
_armada = Inspector.CommandBars.Add(
"Armada", MsoBarPosition.msoBarTop, false, true);_sendButton = (
CommandBarButton)_armada.Controls.Add(MsoControlType.msoControlButton, 1, missing, missing, true);_sendButton.Caption =
"Send private";_sendButton.Style =
MsoButtonStyle.msoButtonIconAndCaption;_sendButton.FaceId = 1983;
//Register send event handler_sendButton.Click +=
new _CommandBarButtonEvents_ClickEventHandler(_sendButton_Click);_armada.Visible =
true;}
}
}
}
Ben Pryor
Yes, I m also having the same problem.
I have used the same code as given by Blood above.
The problem is that when I open the mail reader window then there is the required button and clicking on it is showing a message. If u will open another inspector (mail reader) then still there is the button but clicking on that button doesn't shows the message.
I don't know why is it not showing the message. Please suggest.
Please reply soon.
Thanks
Vikas Vaidya
bstsms
Eigil,
I have to do something like that and i’ve found a lot of problem to build it. May you send the complete code of that solution to me I promisse that i find the solution for metioned error, i’ll post the solution here.
My mail is rarandas@hotmail.com, if you send me it, i apreciate a lot.
Thanks