RibbonX的Globalization和Outlook中RibbonX的应用
来源:互联网 发布:照片表情识别软件 编辑:程序博客网 时间:2024/05/17 10:05
实现环境:Visual Studio 2010,Office 2010, VSTO 4.0
在Ribbon的Globalization中第一步是要建立相应语言的资源文件,这些资源文件的命名方式是"Resources.[语言代码].resx"如图:
这此资源文件必须方在项目的“Properties”文件夹下(你刚创建是是在项目的根目录下,需要你手动把它移到"Properties"文件夹下)。Resources.resx理论上不存在也是没关系的,不过当系统找不到你指定的语言资源是系统会使用这个资源。所以我认为还是有保留的必要。如图:
在这此资源文件中我们对同下个资源名使用不同的语言进行定义,这样我们就达到了Globalization的目的。
在Outlook针对不同Inspector可以定以不同的Ribbon。其方法是在项目中加入定义的xml文件。请在加入这些文件后将Build Action改成Embedded Resource否则就不能通过程序找到它。如图
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[i], StringComparison.OrdinalIgnoreCase) == 0) { using (StreamReader resourceReader = new StreamReader(asm.GetManifestResourceStream(resourceNames[i]))) { if (resourceReader != null) { return resourceReader.ReadToEnd(); } } } } return null; } #endregion public string GetLabel(Office.IRibbonControl Control) { string result = null; switch (Control.Id) { case "Button1": result = Properties.Resources.ButtonLabel1; break; case "Button2": 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("zh-CN"); if (Text.Equals(Properties.Resources.ComboBoxItem2)) ChangeCulture("en-US"); if (Text.Equals(Properties.Resources.ComboBoxItem3)) ChangeCulture("ja-JP"); } private void ChangeCulture(string CultureName) { CultureInfo objCultureInfo = new CultureInfo(CultureName); Properties.Resources.Culture = objCultureInfo; switch (CultureName) { case "zh-CN": tempText = Properties.Resources.ComboBoxItem1; break; case "en-US": tempText = Properties.Resources.ComboBoxItem2; break; case "ja-JP": tempText = Properties.Resources.ComboBoxItem3; break; } this.ribbon.Invalidate(); //重画ribbon用来刷新Ribbon } /// <summary> /// 意义不大可省略 /// </summary> /// <param name="Control"></param> /// <param name="index"></param> /// <returns></returns> public string GetItemID(Office.IRibbonControl Control, int index) { string result = null; switch (index) { case 0: result = "zh-CN"; break; case 1: result = "en-US"; break; case 2: result = "ja-JP"; break; } return result; } }}
OutlookAddIn25Ribbon.xml
<?xml version="1.0" encoding="UTF-8"?><customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="Ribbon_Load"> <ribbon> <tabs> <tab idMso="TabAddIns"> <group id="OutlookAddIn25Group" label="OutlookAddIn25"> <comboBox id="CultureSelector" getItemLabel="GetItemLabel"getText ="DefaultVaule" getItemCount="GetItemCount" getItemID ="GetItemID" onChange ="CultureSelectorChange"> </comboBox> <button id="Button1" getLabel ="GetLabel"/> </group> </tab> </tabs> </ribbon></customUI>
Mail_Compose.xml
<?xml version="1.0" encoding="UTF-8"?><customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="Ribbon_Load"> <ribbon> <tabs> <tab idMso="TabAddIns"> <group id="OutlookAddIn25Group" label="OutlookAddIn25"> <button id="Button2" getLabel ="GetLabel"/> </group> </tab> </tabs> </ribbon></customUI>
相关资源:http://download.csdn.net/detail/tx_officedev/3924316
- RibbonX的Globalization和Outlook中RibbonX的应用
- 细品RibbonX(7):有效的RibbonX设计
- RibbonX的学习资源
- 细品RibbonX(9):层次分明的RibbonX代码结构
- RibbonX 动态生成ComboBox和DropDown的Item
- 细品RibbonX(5):开放的XML文件格式
- 细品RibbonX(8):自定义Ribbon的“武器库”
- 细品RibbonX(4):认识Office的其他界面元素
- 细品RibbonX(14):核心的OpenXML架构元素
- 如何实现RibbonX功能卡切换的响应事件
- 细品RibbonX(6):初识RibbonX
- 细品RibbonX(16):RibbonX开发基础问答
- 细品RibbonX(17):RibbonX控件概述
- 细品RibbonX(2):认识Office的新界面—功能区(Ribbon)
- RibbonX Image FAQ
- RibbonX Image FAQ
- 《北塔教你做插件 从RibbonX开始》第二讲:首建Ribbon——VSTO的星际穿越
- 《北塔教你做插件 从RibbonX开始》第三讲:再建Ribbon——ATL的实现方法
- 我国DTMB正式成为全球第四个数字电视国际标准
- C#截取电脑全屏和窗体屏幕
- Android Google Map Api Key获取
- iPhone应用 Framework
- spring 定时任务 quartz
- RibbonX的Globalization和Outlook中RibbonX的应用
- fedora16 安装 mplayer
- ARM推出DS-5专业版及ARM Compiler 5.0版,RVDS系列工具包将淡出ARM处理器开发
- eclipse svn插件常见报错信息
- fedora9 每次开机都要手动activ network解决方法
- 十个题目
- JS调用后台方法大全
- 北京六大公共区域可享免费无线上网
- VC++ SetLocalTime与SetSystemTime区别