Office中国论坛/Access中国论坛

标题: 【作业】02课-hehex [打印本页]

作者: hehex    时间: 2014-3-9 16:19
标题: 【作业】02课-hehex
本帖最后由 hehex 于 2014-3-10 20:12 编辑

痛苦挠头中...终于调试成功了。模仿西西老师的做的,使用字典,Ribbon1.cs 代码如下。
环境VS 2012+ Word 2013, 不知道为啥贴代码时候,缩进都没了。
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Microsoft.Office.Tools.Ribbon;

  6. namespace VSTO_homework2
  7. {
  8.     public partial class Ribbon1
  9.     {
  10.         private static string chanel = "91283328";
  11.             // 直接初始化字典
  12.         public static Dictionary<string,string> RoomListVSTO = new Dictionary<string,string>()
  13.         {
  14.             {"1768232513", "接待大厅"},
  15.             {"2175343697", "VSTO培训-初级班(一期)<p style="line-height: 30px; text-indent: 2em;"></p><div align="left">"},
  16. </div>            {"1768402953", "Office教学"},
  17.             {"1768334745", "Access技巧"},
  18.             {"1768335157", "Access事例"},
  19.             {"1768335659", "常见问题"},
  20.             {"1768280937", "学生静音挂机房"}

  21.         };
  22.             
  23.    
  24.      
  25.         private void Ribbon1_Load(object sender, RibbonUIEventArgs e)
  26.         {

  27.         }

  28.         private void galleryYY_ItemsLoading(object sender, RibbonControlEventArgs e)
  29.         {
  30.             ((RibbonGallery)sender).Items.Clear(); //清空RibbonGalley 的Items 集合,为装入动态按钮做准备
  31.          
  32.             AddItemsDic((RibbonGallery)sender); // 调用函数从字典中加入Items集合
  33.         }

  34.         private void AddItemsDic(RibbonGallery rmGallery)
  35.         {
  36.             foreach (var kvItem in RoomListVSTO)
  37.             {
  38.             
  39.                 RibbonDropDownItem rbTemp = this.Factory.CreateRibbonDropDownItem();
  40.                 rbTemp.Label = kvItem.Value; //将键值对中的value 加入RibbonDropDownItem 的Label 属性,就是那些中文显示
  41.                 rbTemp.Tag = kvItem.Key.ToString(); //Key就是那些subid 号, 加入Tag属性 暂存
  42.                 rmGallery.Items.Add(rbTemp);
  43.             
  44.             }
  45.         }

  46.         void EnterYYRoom(string cChanel, string cRoom)
  47.         {
  48.             try
  49.             {
  50.                 //打开YY软件
  51.                 System.Diagnostics.Process.Start("yy://pd-[sid=" + cChanel + "&subid=" + cRoom + "]");

  52.             }
  53.             catch (System.Exception ex)
  54.             {
  55.                 //打开网页版YY
  56.                 System.Diagnostics.Process.Start("http://yy.com/" + cChanel + "/" + cRoom + "?from=");
  57.             }

  58.         }

  59.         private void galleryYY_Click(object sender, RibbonControlEventArgs e)
  60.         {
  61.             EnterYYRoom(chanel, Convert.ToString(galleryYY.SelectedItem.Tag));
  62.         }
  63.     }
  64. }
复制代码






欢迎光临 Office中国论坛/Access中国论坛 (http://www.office-cn.net/) Powered by Discuz! X3.3