关于添加前景 [英] Regarding about Add in for outlook

查看:44
本文介绍了关于添加前景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是代码
当运行该程序时显示此错误

错误1类型"Microsoft.Office.Core.CommandBars"在未引用的程序集中定义.您必须添加对程序集``Office,Version = 7.0.3300.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a''的引用. C:\ Documents and Settings \ kalaingar \ Desktop \ examples.net \ Project1 \ projectkalai \ projectkalai \ Connect.cs 95 13 projectkalai


错误2无法将类型"Microsoft.Office.Core.CommandBars []"隐式转换为"Microsoft.Office.Core.CommandBars [c:\ Documents and Settings \ kalaingar \ Desktop \ Interop.Microsoft.Office.Core.dll" ]''C:\ Documents and Settings \ kalaingar \ Desktop \ examples.net \ Project1 \ projectkalai \ projectkalai \ Connect.cs 95 61 projectkalai




this is the code
when run this program showing this errors

Error 1 The type ''Microsoft.Office.Core.CommandBars'' is defined in an assembly that is not referenced. You must add a reference to assembly ''Office, Version=7.0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a''. C:\Documents and Settings\kalaingar\Desktop\examples.net\Project1\projectkalai\projectkalai\Connect.cs 95 13 projectkalai


Error 2 Cannot implicitly convert type ''Microsoft.Office.Core.CommandBars []'' to ''Microsoft.Office.Core.CommandBars [c:\Documents and Settings\kalaingar\Desktop\Interop.Microsoft.Office.Core.dll]'' C:\Documents and Settings\kalaingar\Desktop\examples.net\Project1\projectkalai\projectkalai\Connect.cs 95 61 projectkalai




public class Connect : Object, Extensibility.IDTExtensibility2
    {
        private Microsoft.Office.Interop.Outlook.Application applicationobject;
        private object addInInstance;
        private CommandBarButton btnLaunch;
        /// <summary>
        ///     Implements the constructor for the Add-in object.
        ///     Place your initialization code within this method.
        /// </summary>
        public Connect()
        {
        }

        /// <summary>
        ///      Implements the OnConnection method of the IDTExtensibility2 interface.
        ///      Receives notification that the Add-in is being loaded.
        /// </summary>
        /// <param term='application'>
        ///      Root object of the host application.
        /// </param>
        /// <param term='connectMode'>
        ///      Describes how the Add-in is being loaded.
        /// </param>
        /// <param term='addInInst'>
        ///      Object representing this Add-in.
        /// </param>
        /// <seealso class='IDTExtensibility2' />
        public void OnConnection(object application, Extensibility.ext_ConnectMode connectMode, object addInInst, ref System.Array custom)
        {

        }

        /// <summary>
        ///     Implements the OnDisconnection method of the IDTExtensibility2 interface.
        ///     Receives notification that the Add-in is being unloaded.
        /// </summary>
        /// <param term='disconnectMode'>
        ///      Describes how the Add-in is being unloaded.
        /// </param>
        /// <param term='custom'>
        ///      Array of parameters that are host application specific.
        /// </param>
        /// <seealso class='IDTExtensibility2' />
        public void OnDisconnection(Extensibility.ext_DisconnectMode disconnectMode, ref System.Array custom)
        {
        }

        /// <summary>
        ///      Implements the OnAddInsUpdate method of the IDTExtensibility2 interface.
        ///      Receives notification that the collection of Add-ins has changed.
        /// </summary>
        /// <param term='custom'>
        ///      Array of parameters that are host application specific.
        /// </param>
        /// <seealso class='IDTExtensibility2' />
        public void OnAddInsUpdate(ref System.Array custom)
        {
        }

        /// <summary>
        ///      Implements the OnStartupComplete method of the IDTExtensibility2 interface.
        ///      Receives notification that the host application has completed loading.
        /// </summary>
        /// <param term='custom'>
        ///      Array of parameters that are host application specific.
        /// </param>
        /// <seealso class='IDTExtensibility2' />
        public void OnStartupComplete(ref System.Array custom)
        {
            //CommandBars commandBar =   (applicationobject.ActiveExplorer().CommandBars);
            Microsoft.Office.Core.CommandBars commandbars = applicationobject.ActiveExplorer().CommandBars;

            try
            {
                btnLaunch = (CommandBarButton)commandbars["Standard"].Controls["HelloWorld"];
            }
            catch
            {
                btnLaunch =(CommandBarButton)commandbars["Standard"].Controls.Add(1, System.Reflection.Missing.Value,System.Reflection.Missing.Value,System.Reflection.Missing.Value,System.Reflection.Missing.Value);
                btnLaunch.Caption = "Hello World Browser!";
                btnLaunch.Style = MsoButtonStyle.msoButtonCaption;
            }
            btnLaunch.Tag = "This is hello world Browser";
            btnLaunch.OnAction = "!<EMailStatsAddIn.Connect>";
            btnLaunch.Visible = true;
            btnLaunch.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(btnLaunch_Click);


        }

        /// <summary>
        ///      Implements the OnBeginShutdown method of the IDTExtensibility2 interface.
        ///      Receives notification that the host application is being unloaded.
        /// </summary>
        /// <param term='custom'>
        ///      Array of parameters that are host application specific.
        /// </param>
        /// <seealso class='IDTExtensibility2' />
        public void OnBeginShutdown(ref System.Array custom)
        {
            CommandBars commandBars = applicationobject.ActiveExplorer().CommandBars;
            try
            {
                commandBars["Standard"].Controls["HelloWorld"].Delete(System.Reflection.Missing.Value);
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private void btnLaunch_Click(Microsoft.Office.Core.CommandBarButton Ctrl,
            ref bool CancelDefault)
        {
            try
            {
                frmHelloWorld objfrmHelloWorld = new frmHelloWorld();
                objfrmHelloWorld.Show();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        //private object applicationObject;
        //private object addInInstance;
    }


试试
{
commandBars ["Standard"].Controls ["HelloWorld"].Delete(System.Reflection.Missing.Value);
}
捕获(System.Exception ex)
{
MessageBox.Show(ex.Message);
}
}
私人void btnLaunch_Click(Microsoft.Office.Core.CommandBarButton Ctrl,
ref bool CancelDefault)
{
试试
{
frmHelloWorld objfrmHelloWorld =新的frmHelloWorld();
objfrmHelloWorld.Show();
}
catch(ex ex例外)
{
MessageBox.Show(ex.Message);
}
}

//私有对象applicationObject;
//私有对象addInInstance;
}
试试
{
commandBars ["Standard"].Controls ["HelloWorld"].Delete(System.Reflection.Missing.Value);
}
捕获(System.Exception ex)
{
MessageBox.Show(ex.Message);
}
}
私人void btnLaunch_Click(Microsoft.Office.Core.CommandBarButton Ctrl,
ref bool CancelDefault)
{
试试
{
frmHelloWorld objfrmHelloWorld =新的frmHelloWorld();
objfrmHelloWorld.Show();
}
catch(ex ex例外)
{
MessageBox.Show(ex.Message);
}
}

//私有对象applicationObject;
//私有对象addInInstance;
}


try
{
commandBars["Standard"].Controls["HelloWorld"].Delete(System.Reflection.Missing.Value);
}
catch (System.Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void btnLaunch_Click(Microsoft.Office.Core.CommandBarButton Ctrl,
ref bool CancelDefault)
{
try
{
frmHelloWorld objfrmHelloWorld = new frmHelloWorld();
objfrmHelloWorld.Show();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}

//private object applicationObject;
//private object addInInstance;
}
try
{
commandBars["Standard"].Controls["HelloWorld"].Delete(System.Reflection.Missing.Value);
}
catch (System.Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void btnLaunch_Click(Microsoft.Office.Core.CommandBarButton Ctrl,
ref bool CancelDefault)
{
try
{
frmHelloWorld objfrmHelloWorld = new frmHelloWorld();
objfrmHelloWorld.Show();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}

//private object applicationObject;
//private object addInInstance;
}

推荐答案

将库引用添加到错误消息中指定的项目中.转到项目源代码树,然后右键单击引用"以查看操作.
Add the library reference to your project as specified in the error message. Go to your project source tree and right-click on References to see what to do.


这篇关于关于添加前景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆