设为首页 收藏本站
查看: 1284|回复: 0

[经验分享] RibbonX的Globalization和Outlook中RibbonX的应用

[复制链接]

尚未签到

发表于 2015-9-14 08:48:10 | 显示全部楼层 |阅读模式
  实现环境:Visual Studio 2010,Office 2010, VSTO 4.0
  在Ribbon的Globalization中第一步是要建立相应语言的资源文件,这些资源文件的命名方式是"Resources.[语言代码].resx"如图:
DSC0000.gif


  这此资源文件必须方在项目的“Properties”文件夹下(你刚创建是是在项目的根目录下,需要你手动把它移到"Properties"文件夹下)。Resources.resx理论上不存在也是没关系的,不过当系统找不到你指定的语言资源是系统会使用这个资源。所以我认为还是有保留的必要。如图:
DSC0001.gif


  在这此资源文件中我们对同下个资源名使用不同的语言进行定义,这样我们就达到了Globalization的目的。
  在Outlook针对不同Inspector可以定以不同的Ribbon。其方法是在项目中加入定义的xml文件。请在加入这些文件后将Build Action改成Embedded Resource否则就不能通过程序找到它。如图
DSC0002.gif
  Ribbon的控制代码:
  

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using Office = Microsoft.Office.Core;
using System.Windows.Forms;
using System.Globalization;
// TODO:  Follow these steps to enable the Ribbon (XML) item:
// 1: Copy the following code block into the ThisAddin, ThisWorkbook, or
//  ThisDocument class.
//  protected override Microsoft.Office.Core.IRibbonExtensibility
//CreateRibbonExtensibilityObject()
//  {
//      return new OutlookAddIn25Ribbon();
//  }
// 2. Create callback methods in the "Ribbon Callbacks" region of this class
//  to handle user
//    actions, such as clicking a button. Note: if you have exported this Ribbon
//    from the Ribbon designer,
//    move your code from the event handlers to the callback methods and modify
//    the code to work with the
//    Ribbon extensibility (RibbonX) programming model.
// 3. Assign attributes to the control tags in the Ribbon XML file to identify
//    the appropriate callback methods in your code.  
// For more information, see the Ribbon XML documentation in the Visual Studio
// Tools for Office Help.

namespace OutlookAddIn25
{
[ComVisible(true)]
public class OutlookAddIn25Ribbon : Office.IRibbonExtensibility
{
private Office.IRibbonUI ribbon;
private bool flag;          //用来标识初始状态
private string tempText;    //用来记录用户的选择
public OutlookAddIn25Ribbon()
{
flag = false;
}
#region IRibbonExtensibility Members
public string GetCustomUI(string ribbonID)
{
string result = null;
/*
* Ribbon IDMessage class
* Microsoft.OMS.MMS.ComposeIPM.Note.Mobile.MMS.*
* Microsoft.OMS.MMS.ReadIPM.Note.Mobile.MMS.*
* Microsoft.OMS.SMS.ComposeIPM.Note.Mobile.SMS.*
* Microsoft.OMS.SMS.ReadIPM.Note.Mobile.SMS.*
* Microsoft.Outlook.AppointmentIPM.Appointment.*
* Microsoft.Outlook.Contact IPM.Contact.*
* Microsoft.Outlook.DistributionList IPM.DistList.*
* Microsoft.Outlook.Journal IPM.Activity.*
* Microsoft.Outlook.Mail.Compose IPM.Note.*
* Microsoft.Outlook.Mail.Read IPM.Note.*
* Microsoft.Outlook.MeetingRequest.Read IPM.Schedule.Meeting.Request
* IPM.Schedule.Meeting.Canceled
* Microsoft.Outlook.MeetingRequest.Send IPM.Schedule.Meeting.Request
* Microsoft.Outlook.Post.Compose IPM.Post.*
* Microsoft.Outlook.Post.Read IPM.Post.*
* Microsoft.Outlook.Report IPM.Report.*
* Microsoft.Outlook.Resend IPM.Resend.*
* Microsoft.Outlook.Response.Compose IPM.Schedule.Meeting.Resp.*
* Microsoft.Outlook.Response.CounterPropose IPM.Schedule.Meeting.Resp.*
* Microsoft.Outlook.Response.Read IPM.Schedule.Meeting.Resp.*
* Microsoft.Outlook.RSS IPM.Post.Rss.*
* Microsoft.Outlook.Sharing.Compose IPM.Sharing.*
* Microsoft.Outlook.Sharing.Read IPM.Sharing.*
* Microsoft.Outlook.Task IPM.Task.*
* IPM.TaskRequest.*
* Microsoft.Outlook.Explorer Not applicable. Use this ribbon
* ID to return XML markup for
* explorer ribbons, context menus,
*and Backstage view.
* Reference Url: http://msdn.microsoft.com/en-us/library/ee692172.aspx for 2010
* Reference Url: http://msdn.microsoft.com/en-us/library/bb226712.aspx for 2007
*/
switch (ribbonID)
{
case "Microsoft.Outlook.Explorer":
result = GetResourceText(
"OutlookAddIn25.OutlookAddIn25Ribbon.xml");
break;
case "Microsoft.Outlook.Mail.Compose":
result = GetResourceText("OutlookAddIn25.Mail_Compose.xml");
break;
}
return result;
}
#endregion
#region Ribbon Callbacks
//Create callback methods here. For more information about adding
//callback methods, select the Ribbon XML item in Solution Explorer
//and then press F1
public void Ribbon_Load(Office.IRibbonUI ribbonUI)
{
this.ribbon = ribbonUI;
}
#endregion
#region Helpers
private static string GetResourceText(string resourceName)
{
Assembly asm = Assembly.GetExecutingAssembly();
string[] resourceNames = asm.GetManifestResourceNames();
for (int i = 0; i < resourceNames.Length; ++i)
{
if (string.Compare(resourceName, resourceNames,
StringComparison.OrdinalIgnoreCase) == 0)
{
using (StreamReader resourceReader = new StreamReader(
asm.GetManifestResourceStream(resourceNames)))
{
if (resourceReader != null)
{
return resourceReader.ReadToEnd();
}
}
}
}
return null;
}
#endregion
public string GetLabel(Office.IRibbonControl Control)
{
string result = null;
switch (Control.Id)
{
case &quot;Button1&quot;:
result = Properties.Resources.ButtonLabel1;
break;
case &quot;Button2&quot;:
result = Properties.Resources.ButtonLabel2;
break;
}
return result;
}
public string DefaultVaule(Office.IRibbonControl Control)
{
if (!flag)
{
flag = true;
return Properties.Resources.ComboBoxItem1;  //初始状态
}
else
return tempText;    //使用用户的选择
}
public string GetItemLabel(Office.IRibbonControl Control, int index)
{
string result = null;
switch (index)
{
case 0:
result = Properties.Resources.ComboBoxItem1;
break;
case 1:
result = Properties.Resources.ComboBoxItem2;
break;
case 2:
result = Properties.Resources.ComboBoxItem3;
break;
}
return result;
}
public int GetItemCount(Office.IRibbonControl Control)
{
return 3;
}
public void CultureSelectorChange(Office.IRibbonControl Control,
string Text)
{
if (Text.Equals(Properties.Resources.ComboBoxItem1))
ChangeCulture(&quot;zh-CN&quot;);
if (Text.Equals(Properties.Resources.ComboBoxItem2))
ChangeCulture(&quot;en-US&quot;);
if (Text.Equals(Properties.Resources.ComboBoxItem3))
ChangeCulture(&quot;ja-JP&quot;);
}
private void ChangeCulture(string CultureName)
{
CultureInfo objCultureInfo = new CultureInfo(CultureName);
Properties.Resources.Culture = objCultureInfo;
switch (CultureName)
{
case &quot;zh-CN&quot;:
tempText = Properties.Resources.ComboBoxItem1;
break;
case &quot;en-US&quot;:
tempText = Properties.Resources.ComboBoxItem2;
break;
case &quot;ja-JP&quot;:
tempText = Properties.Resources.ComboBoxItem3;
break;
}
this.ribbon.Invalidate();   //重画ribbon用来刷新Ribbon
}
/// <summary>
/// 意义不大可省略
/// </summary>
/// <param name=&quot;Control&quot;></param>
/// <param name=&quot;index&quot;></param>
/// <returns></returns>
public string GetItemID(Office.IRibbonControl Control, int index)
{
string result = null;
switch (index)
{
case 0:
result = &quot;zh-CN&quot;;
break;
case 1:
result = &quot;en-US&quot;;
break;
case 2:
result = &quot;ja-JP&quot;;
break;
}
return result;
}
}
}

OutlookAddIn25Ribbon.xml
  
  

<?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?>
<customUI xmlns=&quot;http://schemas.microsoft.com/office/2009/07/customui&quot;
onLoad=&quot;Ribbon_Load&quot;>
<ribbon>
<tabs>
<tab idMso=&quot;TabAddIns&quot;>
<group id=&quot;OutlookAddIn25Group&quot;
label=&quot;OutlookAddIn25&quot;>
<comboBox id=&quot;CultureSelector&quot; getItemLabel=&quot;GetItemLabel&quot;
getText =&quot;DefaultVaule&quot; getItemCount=&quot;GetItemCount&quot; getItemID =&quot;GetItemID&quot;
onChange =&quot;CultureSelectorChange&quot;>
</comboBox>
<button id=&quot;Button1&quot; getLabel =&quot;GetLabel&quot;/>
</group>
</tab>
</tabs>
</ribbon>
</customUI>

Mail_Compose.xml
  
  

<?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?>
<customUI xmlns=&quot;http://schemas.microsoft.com/office/2009/07/customui&quot;
onLoad=&quot;Ribbon_Load&quot;>
<ribbon>
<tabs>
<tab idMso=&quot;TabAddIns&quot;>
<group id=&quot;OutlookAddIn25Group&quot;
label=&quot;OutlookAddIn25&quot;>
<button id=&quot;Button2&quot; getLabel =&quot;GetLabel&quot;/>
</group>
</tab>
</tabs>
</ribbon>
</customUI>

相关资源:http://download.iyunv.com/detail/tx_officedev/3924316
  

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.iyunv.com/thread-113267-1-1.html 上篇帖子: Microsfot Firewall Client引起Outlook Express无法收发邮件的问题 下篇帖子: 【转】outlook 2007 如何设置开机自动启动
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表