Click here to Skip to main content
15,887,027 members
Home / Discussions / C#
   

C#

 
QuestionC# DATAGRIDVIEW CELL EDIT Pin
mubasit23-Apr-14 19:58
mubasit23-Apr-14 19:58 
AnswerRe: C# DATAGRIDVIEW CELL EDIT Pin
Eddy Vluggen23-Apr-14 21:52
professionalEddy Vluggen23-Apr-14 21:52 
QuestionGetting value of SHDocVw.InternetExplorer Pin
Kaveh Yazdi Nezhad23-Apr-14 17:34
Kaveh Yazdi Nezhad23-Apr-14 17:34 
AnswerRe: Getting value of SHDocVw.InternetExplorer Pin
Bernhard Hiller23-Apr-14 22:18
Bernhard Hiller23-Apr-14 22:18 
AnswerRe: Getting value of SHDocVw.InternetExplorer Pin
Kaveh Yazdi Nezhad26-Apr-14 6:23
Kaveh Yazdi Nezhad26-Apr-14 6:23 
QuestionHow to Collect Microsoft Remote Connectivity Analyzer Results Pin
lesponce23-Apr-14 15:51
lesponce23-Apr-14 15:51 
AnswerRe: How to Collect Microsoft Remote Connectivity Analyzer Results Pin
Eddy Vluggen23-Apr-14 22:43
professionalEddy Vluggen23-Apr-14 22:43 
QuestionHow to add Outlook toolbar under the subject line in C# add-in? Pin
Artem Moroz23-Apr-14 12:46
Artem Moroz23-Apr-14 12:46 
I need to write an Outlook 2003-2010 plugin using C# that adds two buttons to the Message Ribbon Bar (#1 on the picture) and a several buttons toolbar or a Form Region under the "Subject" line (#2 on the picture).

See image here: http://i.piccy.info/i9/8ccdf69246fbcd9171d488747c6ea189/1398291704/206810/736482/editmessage.png[^]

Currently I managed to add a button to the Ribbon toolbar, but it appears in the "Add-ins" Ribbon Bar. How do I add buttons to the "Message" Ribbon Bar?

And how do I add the Toolbar #2 ? I currently have no clue about how to add it.

Please help me!

I now have the following code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using Outlook = Microsoft.Office.Interop.Outlook;
using Office = Microsoft.Office.Core;
using System.Windows.Forms;

namespace SendLaterToolbar
{
    public partial class ThisAddIn
    {
        Office.CommandBar newToolBar;
        Office.CommandBarButton firstButton;
        Office.CommandBarButton secondButton;
        Outlook.Explorers selectExplorers;
        Outlook.Inspectors inspectors;
        Office.CommandBarButton _objEmailToolBarButton;

        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            selectExplorers = this.Application.Explorers;
            inspectors = this.Application.Inspectors;
            selectExplorers.NewExplorer += new Outlook.ExplorersEvents_NewExplorerEventHandler(newExplorer_Event);
            inspectors.NewInspector += new Microsoft.Office.Interop.Outlook.InspectorsEvents_NewInspectorEventHandler(AddToEmail);
            AddToolbar();
        }

        private void newExplorer_Event(Outlook.Explorer new_Explorer)
        {
            ((Outlook._Explorer)new_Explorer).Activate();
            newToolBar = null;
            AddToolbar();
        }

        private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
        {

        }

        private void AddToolbar()
        {

            if (newToolBar == null)
            {
                Office.CommandBars cmdBars =
                    this.Application.ActiveExplorer().CommandBars;
                newToolBar = cmdBars.Add("NewToolBar",
                    Office.MsoBarPosition.msoBarTop, false, true);
            }
            try
            {
                Office.CommandBarButton button_1 =
                    (Office.CommandBarButton)newToolBar.Controls
                    .Add(1, missing, missing, missing, missing);
                button_1.Style = Office
                    .MsoButtonStyle.msoButtonCaption;
                button_1.Caption = "Button 1";
                button_1.Tag = "Button1";
                if (this.firstButton == null)
                {
                    this.firstButton = button_1;
                    firstButton.Click += new Office.
                        _CommandBarButtonEvents_ClickEventHandler
                        (ButtonClick);
                }

                Office.CommandBarButton button_2 = (Office
                    .CommandBarButton)newToolBar.Controls.Add
                    (1, missing, missing, missing, missing);
                button_2.Style = Office
                    .MsoButtonStyle.msoButtonCaption;
                button_2.Caption = "Button 2";
                button_2.Tag = "Button2";
                newToolBar.Visible = true;
                if (this.secondButton == null)
                {
                    this.secondButton = button_2;
                    secondButton.Click += new Office.
                        _CommandBarButtonEvents_ClickEventHandler
                        (ButtonClick);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void AddToEmail(Microsoft.Office.Interop.Outlook.Inspector Inspector)
        {
            Outlook.MailItem _ObjMailItem = (Outlook.MailItem)Inspector.CurrentItem;

            if (Inspector.CurrentItem is Outlook.MailItem)
            {
                _ObjMailItem = (Outlook.MailItem)Inspector.CurrentItem;
                bool IsExists = false;

                foreach (Office.CommandBar _ObjCmd in Inspector.CommandBars)
                {
                    if (_ObjCmd.Name == "MyEmailToolBar")
                    {
                        IsExists = true;
                        _ObjCmd.Delete();
                    }
                }

                Office.CommandBar _ObjCommandBar = Inspector.CommandBars.Add("MyEmailToolBar", Office.MsoBarPosition.msoBarBottom, false, true);
                _objEmailToolBarButton = (Office.CommandBarButton)_ObjCommandBar.Controls.Add(Office.MsoControlType.msoControlButton, 1, missing, missing, true);

                if (!IsExists)
                {
                    _objEmailToolBarButton.Caption = "My Email ToolBar Button";
                    _objEmailToolBarButton.Style = Office.MsoButtonStyle.msoButtonIconAndCaptionBelow;
                    _objEmailToolBarButton.FaceId = 500;
                    _objEmailToolBarButton.Click += new Office._CommandBarButtonEvents_ClickEventHandler(_objEmailToolBarButton_Click);
                    _ObjCommandBar.Visible = true;
                }
            }
        }


        private void ButtonClick(Office.CommandBarButton ctrl, ref bool cancel)
        {
            MessageBox.Show("You clicked: " + ctrl.Caption);
        }

        private void _objEmailToolBarButton_Click(Office.CommandBarButton ctrl, ref bool cancel)
        {
            MessageBox.Show("My Email ToolBar ...");
        }

        #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(ThisAddIn_Startup);
            this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
        }

        #endregion
    }
}

AnswerRe: How to add Outlook toolbar under the subject line in C# add-in? Pin
Eddy Vluggen23-Apr-14 22:45
professionalEddy Vluggen23-Apr-14 22:45 
GeneralRe: How to add Outlook toolbar under the subject line in C# add-in? Pin
Artem Moroz26-Apr-14 8:56
Artem Moroz26-Apr-14 8:56 
QuestionHow to Open new Form when click on TreeNode? Pin
aahamdan23-Apr-14 10:10
aahamdan23-Apr-14 10:10 
AnswerRe: How to Open new Form when click on TreeNode? Pin
Mycroft Holmes23-Apr-14 12:56
professionalMycroft Holmes23-Apr-14 12:56 
GeneralRe: How to Open new Form when click on TreeNode? Pin
aahamdan23-Apr-14 22:23
aahamdan23-Apr-14 22:23 
AnswerRe: How to Open new Form when click on TreeNode? Pin
UGUR KIZILKAYA24-Apr-14 4:55
UGUR KIZILKAYA24-Apr-14 4:55 
AnswerRe: How to Open new Form when click on TreeNode? Pin
BillWoodruff25-Apr-14 20:17
professionalBillWoodruff25-Apr-14 20:17 
QuestionWeb API action null data on post when deployed to production Pin
Basilfa23-Apr-14 0:43
Basilfa23-Apr-14 0:43 
Question"Combined Type" - Generics - something else? Pin
Bernhard Hiller22-Apr-14 23:55
Bernhard Hiller22-Apr-14 23:55 
QuestionRe: "Combined Type" - Generics - something else? Pin
Eddy Vluggen23-Apr-14 0:35
professionalEddy Vluggen23-Apr-14 0:35 
AnswerRe: "Combined Type" - Generics - something else? Pin
Bernhard Hiller23-Apr-14 0:54
Bernhard Hiller23-Apr-14 0:54 
AnswerRe: "Combined Type" - Generics - something else? PinPopular
Richard Deeming23-Apr-14 1:18
mveRichard Deeming23-Apr-14 1:18 
GeneralRe: "Combined Type" - Generics - something else? Pin
Bernhard Hiller23-Apr-14 2:28
Bernhard Hiller23-Apr-14 2:28 
Question"Configuration system failed to initialize" Pin
AshwiniSH22-Apr-14 23:32
professionalAshwiniSH22-Apr-14 23:32 
AnswerRe: "Configuration system failed to initialize" Pin
Bernhard Hiller22-Apr-14 23:56
Bernhard Hiller22-Apr-14 23:56 
GeneralRe: "Configuration system failed to initialize" Pin
AshwiniSH24-Apr-14 21:51
professionalAshwiniSH24-Apr-14 21:51 
Questionhow to use events using Base class Pin
Member 1034709222-Apr-14 15:44
Member 1034709222-Apr-14 15:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.