本示例演示了如何获取更改后的系统CultureInfo,而无需重新启动Word程序加载Add-In。
示例代码:
using System;
using Microsoft.Office.Tools.Ribbon;
using System.Globalization;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace WordAddIn1
{
public partial class Ribbon1
{
private void Ribbon1_Load(object sender, RibbonUIEventArgs e)
{
}
private void button1_Click(object sender, RibbonControlEventArgs e)
{
// use P/Invoke to get local Id
int lcid = Convert.ToInt32(GetUserDefaultLCID());
MessageBox.Show(lcid.ToString());
// get the culture info
CultureInfo ci = new CultureInfo(lcid);
MessageBox.Show(ci.ToString());
}
[DllImport("kernel32.dll")]
static extern uint GetUserDefaultLCID();
}
}
运行效果
工程下载:
http://download.youkuaiyun.com/detail/songpengpeng20100202/3977636