Office中国论坛/Access中国论坛
标题:
【作业】02课-Jiakun2014
[打印本页]
作者:
Jiakun2014
时间:
2014-3-14 07:51
学习6楼hehex的帖子做的,显示文本标签
[attach]53554[/attach]
代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Office.Tools.Ribbon;
namespace wDynamicButton
{
public partial class DynamicButton
{
private static Dictionary<string, string> ButtonList = new Dictionary<string, string>()
{
#region display text only
{"1768232513", "接待大厅"},
{"2175343697", "VSTO培训-初级班(一期)"},
{"1768402953", "Office教学"},
{"1768334745", "Access技巧"},
{"1768335157", "Access事例"},
{"1768335659", "常见问题"},
{"1768280937", "学生静音挂机房"}
#endregion
};
private void gallery1_ItemsLoading(object sender, RibbonControlEventArgs e)
{
gallery1.Items.Clear();
AddItems(gallery1);
}
private void AddItems(RibbonGallery rmList)
{
//string s_rm, s_imge;
foreach (var bList in ButtonList)
{
RibbonDropDownItem bTemp = this.Factory.CreateRibbonDropDownItem();
bTemp.Tag = bList.Key;
bTemp.Label = bList.Value;
rmList.Items.Add(bTemp);
}
}
void EnterYYRoom(string id, string subid)
{
System.Diagnostics.Process.Start("http://yy.com/" + id + "/" + subid + "?from=");
}
private void DynamicButton_Load(object sender, RibbonUIEventArgs e)
{
}
private void gallery1_Click(object sender, RibbonControlEventArgs e)
{
EnterYYRoom("91283328", Convert.ToString(gallery1.SelectedItem.Tag));
}
}
}
复制代码
学习9楼Amas添加Items做的,显示图片及文本标签
[attach]53555[/attach]
代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Office.Tools.Ribbon;
using System.Drawing;
using System.Resources;
namespace wDynamicButton
{
public partial class DynamicButton
{
private static Dictionary<string, string> ButtonList = new Dictionary<string, string>()
{
#region display image icon
{"1768232513", "接待大厅|support"},
{"2175343697", "VSTO培训-初级班(一期)|vsto"},
{"1768402953", "Office教学|office"},
{"1768335157", "Access事例|access"},
{"1768335659", "常见问题|faq"},
{"1768280937", "学生静音挂机房|mute"}
#endregion
};
private void gallery1_ItemsLoading(object sender, RibbonControlEventArgs e)
{
gallery1.Items.Clear();
AddItems(gallery1);
}
private void AddItems(RibbonGallery rmList)
{
string s_rm, s_imge;
foreach (var bList in ButtonList)
{
RibbonDropDownItem bTemp = this.Factory.CreateRibbonDropDownItem();
#region extract RoomName and ImageName for displaying image part
s_rm = bList.Value.Substring(0, bList.Value.IndexOf("|"));
s_imge = bList.Value.Substring(bList.Value.IndexOf("|") + 1);
#endregion
bTemp.Tag = bList.Key;
#region assign Label and Image for displaying image part
bTemp.Label = s_rm;
bTemp.Image = Properties.Resources.ResourceManager.GetObject(s_imge) as Image;
#endregion
rmList.Items.Add(bTemp);
}
}
void EnterYYRoom(string id, string subid)
{
System.Diagnostics.Process.Start("http://yy.com/" + id + "/" + subid + "?from=");
}
private void DynamicButton_Load(object sender, RibbonUIEventArgs e)
{
}
private void gallery1_Click(object sender, RibbonControlEventArgs e)
{
EnterYYRoom("91283328", Convert.ToString(gallery1.SelectedItem.Tag));
}
}
}
复制代码
其它参考:
1,功能区对象模型概述
http://msdn.microsoft.com/zh-cn/library/bb608623%28v=vs.100%29.aspx
复制代码
2,C# How to Add and Use Images from Resources
http://www.youtube.com/watch?v=LQMDsJgMXhE
复制代码
作者:
faunus
时间:
2014-3-14 17:17
作业很认真,多给一V
欢迎光临 Office中国论坛/Access中国论坛 (http://www.office-cn.net/)
Powered by Discuz! X3.3