Office中国论坛/Access中国论坛
标题:
【作业】02课-hehex
[打印本页]
作者:
hehex
时间:
2014-3-9 16:19
标题:
【作业】02课-hehex
本帖最后由 hehex 于 2014-3-10 20:12 编辑
痛苦挠头中...终于调试成功了。模仿西西老师的做的,使用字典,Ribbon1.cs 代码如下。
环境VS 2012+ Word 2013, 不知道为啥贴代码时候,缩进都没了。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Office.Tools.Ribbon;
namespace VSTO_homework2
{
public partial class Ribbon1
{
private static string chanel = "91283328";
// 直接初始化字典
public static Dictionary<string,string> RoomListVSTO = new Dictionary<string,string>()
{
{"1768232513", "接待大厅"},
{"2175343697", "VSTO培训-初级班(一期)<p style="line-height: 30px; text-indent: 2em;"></p><div align="left">"},
</div> {"1768402953", "Office教学"},
{"1768334745", "Access技巧"},
{"1768335157", "Access事例"},
{"1768335659", "常见问题"},
{"1768280937", "学生静音挂机房"}
};
private void Ribbon1_Load(object sender, RibbonUIEventArgs e)
{
}
private void galleryYY_ItemsLoading(object sender, RibbonControlEventArgs e)
{
((RibbonGallery)sender).Items.Clear(); //清空RibbonGalley 的Items 集合,为装入动态按钮做准备
AddItemsDic((RibbonGallery)sender); // 调用函数从字典中加入Items集合
}
private void AddItemsDic(RibbonGallery rmGallery)
{
foreach (var kvItem in RoomListVSTO)
{
RibbonDropDownItem rbTemp = this.Factory.CreateRibbonDropDownItem();
rbTemp.Label = kvItem.Value; //将键值对中的value 加入RibbonDropDownItem 的Label 属性,就是那些中文显示
rbTemp.Tag = kvItem.Key.ToString(); //Key就是那些subid 号, 加入Tag属性 暂存
rmGallery.Items.Add(rbTemp);
}
}
void EnterYYRoom(string cChanel, string cRoom)
{
try
{
//打开YY软件
System.Diagnostics.Process.Start("yy://pd-[sid=" + cChanel + "&subid=" + cRoom + "]");
}
catch (System.Exception ex)
{
//打开网页版YY
System.Diagnostics.Process.Start("http://yy.com/" + cChanel + "/" + cRoom + "?from=");
}
}
private void galleryYY_Click(object sender, RibbonControlEventArgs e)
{
EnterYYRoom(chanel, Convert.ToString(galleryYY.SelectedItem.Tag));
}
}
}
复制代码
欢迎光临 Office中国论坛/Access中国论坛 (http://www.office-cn.net/)
Powered by Discuz! X3.3