最近项目中用到RadialMenu,效果图如下所示:(图片因为公司要求不能挂出来,所以截取中一部分了)

闲下来就对,devexpress中的RedialMenu的使用总结一下。

第一:假设RedialMenu中全部是BarButtonItem的情况。

第二:假设RedialMenu中有BarSubItem也有BarButtonItem的情况。

第三:假设先按首字母进行归类,首字母全部为BarSubItem,其中的子类为BarButtonItem。

第一中情况的效果图如下所示

调用代码:

                radialMenu.InitDate(barManager, , ItemClick, this);
radialMenu.AddSubItemAndItem(list);

其中红色字体list是初始化数据:

 List<string> list = new List<string>();
for (int i = ; i <= ; i++)
{
list.Add("啊受命于天" + i);
}
for (int i = ; i <= ; i++)
{
list.Add("吧受命于天" + i);
}
for (int i = ; i <= ; i++)
{
list.Add("才受命于天" + i);
}
for (int i = ; i <= ; i++)
{
list.Add("的受命于天" + i);
}
for (int i = ; i <= ; i++)
{
list.Add("额受命于天" + i);
}
for (int i = ; i <= ; i++)
{
list.Add("飞受命于天" + i);
} for (int i = ; i <= ; i++)
{
list.Add("个受命于天" + i);
}
for (int i = ; i <= ; i++)
{
list.Add("好吧受命于天" + i);
}
for (int i = ; i <= ; i++)
{
list.Add("就才受命于天" + i);
}
for (int i = ; i <= ; i++)
{
list.Add("看的受命于天" + i);
}
for (int i = ; i <= ; i++)
{
list.Add("了额受命于天" + i);
}
for (int i = ; i <= ; i++)
{
list.Add("吗飞受命于天" + i);
} for (int i = ; i <= ; i++)
{
list.Add("你受命于天" + i);
}
for (int i = ; i <= ; i++)
{
list.Add("哦吧受命于天" + i);
}
for (int i = ; i <= ; i++)
{
list.Add("平才受命于天" + i);
}
for (int i = ; i <= ; i++)
{
list.Add("去的受命于天" + i);
}
for (int i = ; i <= ; i++)
{
list.Add("人额受命于天" + i);
}
for (int i = ; i <= ; i++)
{
list.Add("是飞受命于天" + i);
} for (int i = ; i <= ; i++)
{
list.Add("他才受命于天" + i);
}
for (int i = ; i <= ; i++)
{
list.Add("我的受命于天" + i);
}
for (int i = ; i <= ; i++)
{
list.Add("想受命于天" + i);
}
for (int i = ; i <= ; i++)
{
list.Add("一飞受命于天" + i);
}
for (int i = ; i <= ; i++)
{
list.Add("在飞受命于天" + i);
}

第二中情况的效果图如下所示

调用代码:

                List<string> list = new List<string>();
Dictionary<string, List<string>> dic = new Dictionary<string, List<string>>();
for (int i = ; i < ; i++)
{
list.Clear();
for (int j = ; j <= i + ; j++)
{
list.Add("受命于天" + j);
}
if (i % == )
list.Clear();
dic["受命于天" + i] = new List<string>(list);
}
radialMenu.InitDate(barManager, , ItemClick, this);
radialMenu.AddSubItemAndItem(dic);

第三中情况的效果图如下所示

按汉子首字母拼英进行归类,其中的子项归为首字母中。

调用代码:

                radialMenu.InitDate(barManager, , ItemClick, this);
radialMenu.AddSubItemAndItem(list);

代码中的list与第一种情况下的list一样。

新建RadialMenu的扩展方法InitDate和AddSubItemAndItem。代码如下所示:

   public static class RadialMenuExpression
{
private static bool isInit = false;
private static int index = ;
private static int ItemCount = ;
private static DevExpress.XtraBars.Ribbon.RadialMenu radialMenu;
private static BarManager barManager;
private static Action<object, ItemClickEventArgs> itemClick;
/// <summary>
/// 初始化
/// </summary>
/// <param name="barManagerExpression">barManager</param>
/// <param name="itemCountExpression">显示个数</param>
/// <param name="itemClickExpression">点击事件</param>
/// <param name="fromExpression">所属窗体</param>
/// <returns></returns>
public static bool InitDate(this DevExpress.XtraBars.Ribbon.RadialMenu radialMenuExpression, BarManager barManagerExpression, int itemCountExpression, Action<object, ItemClickEventArgs> itemClickExpression, Control fromExpression)
{
if (radialMenuExpression == null || barManagerExpression == null || itemCountExpression <= || itemClickExpression == null)
return false;
radialMenu = radialMenuExpression;
barManager = barManagerExpression;
ItemCount = itemCountExpression;
itemClick = itemClickExpression;
InitRadialMenu(fromExpression);
isInit = true;
return true;
}
private static void InitRadialMenu(Control from)
{
//radialMenu = new DevExpress.XtraBars.Ribbon.RadialMenu();
radialMenu.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)()))), ((int)(((byte)()))), ((int)(((byte)()))));
radialMenu.MenuColor = System.Drawing.Color.Teal;
barManager = new BarManager();
barManager.Form = from;
DevExpress.XtraBars.BarDockControl barDockControlLeft = new BarDockControl();
DevExpress.XtraBars.BarDockControl barDockControlRight = new BarDockControl();
DevExpress.XtraBars.BarDockControl barDockControlBottom = new BarDockControl();
DevExpress.XtraBars.BarDockControl barDockControlTop = new BarDockControl(); barDockControlTop.CausesValidation = false;
barDockControlTop.Dock = System.Windows.Forms.DockStyle.Top;
barDockControlTop.Location = new System.Drawing.Point(, );
barDockControlTop.Size = new System.Drawing.Size(, ); barDockControlBottom.CausesValidation = false;
barDockControlBottom.Dock = System.Windows.Forms.DockStyle.Bottom;
barDockControlBottom.Location = new System.Drawing.Point(, );
barDockControlBottom.Size = new System.Drawing.Size(, ); barDockControlLeft.CausesValidation = false;
barDockControlLeft.Dock = System.Windows.Forms.DockStyle.Left;
barDockControlLeft.Location = new System.Drawing.Point(, );
barDockControlLeft.Size = new System.Drawing.Size(, ); barDockControlRight.CausesValidation = false;
barDockControlRight.Dock = System.Windows.Forms.DockStyle.Right;
barDockControlRight.Location = new System.Drawing.Point(, );
barDockControlRight.Size = new System.Drawing.Size(, );
barManager.DockControls.Add(barDockControlTop);
barManager.DockControls.Add(barDockControlBottom);
barManager.DockControls.Add(barDockControlLeft);
barManager.DockControls.Add(barDockControlRight);
radialMenu.Manager = barManager;
//this.barManager.MaxItemId = listName.Count;
}
/// <summary>
/// 初始化
/// </summary>
/// <param name="dic">BarSubItem的名称为dic中key的值,BarSubItem中BarButtonItem的名称为对应的dic中value</param>
/// <param name="itemClick">RadialMenu中BarButtonItem的单击事件</param>
public static void AddSubItemAndBarItem(this DevExpress.XtraBars.Ribbon.RadialMenu radialMenuExpression, Dictionary<string, List<string>> dic)
{
if (!isInit)
return;
BarSubItem subItem = null;
foreach (KeyValuePair<string, List<string>> item in dic)
{
subItem = SetSubItem(item.Key);
if (item.Value.Count <= )
{
AddItem(item.Key, itemClick);
continue;
}
else
AddSubItem(subItem);
List<string> listItemName = item.Value;//.ToList();
int count = ;
foreach (string Itemname in listItemName)
{
count++;
if (subItem == null)
AddItem(Itemname, itemClick);
else
SubItemAddItem(itemClick, Itemname, subItem);
if (count != && count % ItemCount == )
{
BarSubItem subItemTemo = SetSubItem("更多");
SubItemAddSubItem(subItem, subItemTemo);
subItem = subItemTemo;
}
}
}
}
private static BarSubItem SetSubItem(string name)
{
BarSubItem subItem = new BarSubItem();
subItem.Id = index++;
subItem.Caption = name;
subItem.ItemAppearance.Hovered.ForeColor = System.Drawing.Color.Black;
subItem.ItemAppearance.Hovered.Options.UseForeColor = true;
subItem.ItemInMenuAppearance.Hovered.BackColor = System.Drawing.Color.Yellow;
subItem.ItemInMenuAppearance.Hovered.ForeColor = System.Drawing.Color.Black;
subItem.ItemInMenuAppearance.Hovered.Options.UseBackColor = true;
subItem.ItemInMenuAppearance.Hovered.Options.UseForeColor = true;
subItem.ItemInMenuAppearance.Normal.ForeColor = System.Drawing.Color.Yellow;
subItem.ItemInMenuAppearance.Normal.Options.UseForeColor = true;
return subItem;
}
private static BarButtonItem GetBarButtonItem(string name, Action<object, ItemClickEventArgs> itemClick)
{
BarButtonItem item = new BarButtonItem();
item.Id = index++;
item.Caption = name;
item.ItemAppearance.Disabled.ForeColor = System.Drawing.Color.Yellow;
item.ItemAppearance.Disabled.Options.UseForeColor = true;
item.ItemInMenuAppearance.Hovered.BackColor = System.Drawing.Color.Yellow;
item.ItemInMenuAppearance.Hovered.Options.UseBackColor = true;
item.ItemInMenuAppearance.Hovered.Options.UseForeColor = true;
item.ItemInMenuAppearance.Normal.ForeColor = System.Drawing.Color.Yellow;
item.ItemInMenuAppearance.Normal.Options.UseForeColor = true;
item.Name = name;
item.ItemClick += new DevExpress.XtraBars.ItemClickEventHandler(itemClick);
return item;
}
/// <summary>
/// 正常初始化
/// </summary>
/// <param name="name">BarSubItem的名称</param>
/// <param name="listName">RadialMenu中BarButtonItem的名称</param>
/// <param name="itemClick">RadialMenu中BarButtonItem的单击事件</param>
public static void AddSubItemAndBarItem(this DevExpress.XtraBars.Ribbon.RadialMenu radialMenuExpression, string name, List<string> listName)
{
if (!isInit)
return;
BarSubItem subItem = null;
int count = ;
bool flag = false;
foreach (string Itemname in listName)
{
count++;
if (subItem == null)
AddItem(Itemname, itemClick);
else
SubItemAddItem(itemClick, Itemname, subItem);
if (count != && count % ItemCount == )
{
if (!flag)
{
subItem = SetSubItem(name);
AddSubItem(subItem);
flag = true;
}
else
{
BarSubItem subItemTemo = SetSubItem(name);
SubItemAddSubItem(subItem, subItemTemo);
subItem = subItemTemo;
}
count = ;
}
}
}
private static void AddSubItem(BarSubItem subItem)
{
radialMenu.BeginInit();
barManager.BeginInit();
radialMenu.LinksPersistInfo.Add(new LinkPersistInfo(subItem));
barManager.Items.Add(subItem);
radialMenu.EndInit();
barManager.EndInit();
}
private static void SubItemAddSubItem(BarSubItem subItem, BarSubItem addItem)
{
radialMenu.BeginInit();
barManager.BeginInit();
subItem.LinksPersistInfo.Add(new LinkPersistInfo(addItem));
barManager.Items.Add(addItem);
radialMenu.EndInit();
barManager.EndInit();
}
private static void AddItem(string nameItem, Action<object, ItemClickEventArgs> itemClick)
{
radialMenu.BeginInit();
barManager.BeginInit();
BarButtonItem item = GetBarButtonItem(nameItem, itemClick);
radialMenu.LinksPersistInfo.Add(new LinkPersistInfo(item));
barManager.Items.Add(item);
radialMenu.EndInit();
barManager.EndInit();
}
private static void SubItemAddItem(Action<object, ItemClickEventArgs> itemClick, string nameItem, BarSubItem subItem)
{
radialMenu.BeginInit();
barManager.BeginInit();
BarButtonItem item = GetBarButtonItem(nameItem, itemClick);
subItem.LinksPersistInfo.Add(new LinkPersistInfo(item));
barManager.Items.Add(item);
radialMenu.EndInit();
barManager.EndInit();
} /// <summary>
/// 按首字母进行初始化
/// </summary>
/// <param name="listName">RadialMenu中BarButtonItem的名称</param>
/// <param name="itemClick">RadialMenu中BarButtonItem的单击事件</param>
public static void AddSubItemAndBarItem(this DevExpress.XtraBars.Ribbon.RadialMenu radialMenuExpression, List<string> listName)
{
if (!isInit)
return;
List<NameAndLetter> listNameAndLetter = new List<NameAndLetter>();
Dictionary<string, List<NameAndLetter>> dic = new Dictionary<string, List<NameAndLetter>>();
foreach (string name in listName)
{
NameAndLetter item = new NameAndLetter();
item.Name = name;
item.Letter = CNSpellTranslator.GetSpellCode(name);
listNameAndLetter.Add(item);
}
List<string> list = listNameAndLetter.OrderBy(x => x.Letter.Substring(, )).Select(x => x.Letter.Substring(, )).Distinct().ToList();
foreach (string name in list)
{
dic[name] = listNameAndLetter.Where(x => x.Letter.Substring(, ) == name).ToList();
}
SetDictionary(dic);
BarSubItem subItem = null;
foreach (KeyValuePair<string, List<NameAndLetter>> item in dic)
{
subItem = SetSubItem(item.Key);
AddSubItem(subItem);
List<string> listItemName = item.Value.Select(x => x.Name).ToList();
int count = ;
foreach (string Itemname in listItemName)
{
count++;
if (subItem == null)
AddItem(Itemname, itemClick);
else
SubItemAddItem(itemClick, Itemname, subItem);
if (count != && count % ItemCount == )
{
BarSubItem subItemTemo = SetSubItem("更多");
SubItemAddSubItem(subItem, subItemTemo);
subItem = subItemTemo;
}
}
}
}
private static void SetDictionary(Dictionary<string, List<NameAndLetter>> dic, bool flagCount = true)
{
if (dic.Count < )
return;
Dictionary<string, List<NameAndLetter>> dicMin = GetMinDicOrMax(dic, true);
Dictionary<string, List<NameAndLetter>> dicMax = GetMinDicOrMax(dic, true);
string key = "";
List<NameAndLetter> value = new List<NameAndLetter>();
if (dicMax.Count <= && dicMin.Count <= )
return;
foreach (KeyValuePair<string, List<NameAndLetter>> item in dicMin)
{
key += item.Key;
value = value.Concat(item.Value).ToList();
}
foreach (KeyValuePair<string, List<NameAndLetter>> item in dicMax)
{
key += item.Key;
value = value.Concat(item.Value).ToList();
}
dic[key] = value;
if (dic.Count >= )
SetDictionary(dic);
}
private static Dictionary<string, List<NameAndLetter>> GetMinDicOrMax(Dictionary<string, List<NameAndLetter>> dic, bool
isMin)
{
Dictionary<string, List<NameAndLetter>> dicTemp = new Dictionary<string, List<NameAndLetter>>();
if (dic.Count <= )
return dicTemp;
int count = ;
bool flagMinDic = false; foreach (KeyValuePair<string, List<NameAndLetter>> item in dic)
{
int letterCount = item.Value.Count;
if (!flagMinDic)
{
count = item.Value.Count;
dicTemp[item.Key] = item.Value;
flagMinDic = true;
continue;
}
if (isMin)
{
if (letterCount < count)
{
dicTemp.Clear();
dicTemp[item.Key] = item.Value;
}
}
else
{
if (letterCount > count)
{
dicTemp.Clear();
dicTemp[item.Key] = item.Value;
}
}
}
foreach (KeyValuePair<string, List<NameAndLetter>> item in dicTemp)
{
dic.Remove(item.Key);
}
return dicTemp;
} }

获取汉字拼音的类:

    public class CNSpellTranslator
{
/// <summary>
/// 在指定的字符串列表CnStr中检索符合拼音索引字符串
/// </summary>
/// <param name="CnStr">汉字字符串</param>
/// <returns>相对应的汉语拼音首字母串</returns>
public static string GetSpellCode(string CnStr)
{
string strTemp = "";
int iLen = CnStr.Length;
int i = ; for (i = ; i <= iLen - ; i++)
{
strTemp += GetCharSpellCode(CnStr.Substring(i, ));
}
return strTemp;
} /// <summary>
/// 输入是字母还是汉字
/// </summary>
/// <param name="firstKey"></param>
/// <returns></returns>
public static bool IsChar(char firstKey)
{
if ((firstKey >= 'a' && firstKey <= 'z') || (firstKey >= 'A' && firstKey <= 'Z'))
{
return true;
}
return false;
} /// <summary>
/// 得到一个汉字的拼音第一个字母,如果是一个英文字母则直接返回大写字母
/// </summary>
/// <param name="cnChar">单个汉字</param>
/// <returns>单个大写字母</returns>
private static string GetCharSpellCode(string cnChar)
{
long iCnChar; byte[] ZW = Encoding.Default.GetBytes(cnChar); //如果是字母,则直接返回
if (ZW.Length == )
{
return cnChar.ToUpper();
}
// get the array of byte from the single char
int i1 = ZW[];
int i2 = ZW[];
iCnChar = i1 * + i2; //expresstion
//table of the constant list
// 'A'; //45217..45252
// 'B'; //45253..45760
// 'C'; //45761..46317
// 'D'; //46318..46825
// 'E'; //46826..47009
// 'F'; //47010..47296
// 'G'; //47297..47613 // 'H'; //47614..48118
// 'J'; //48119..49061
// 'K'; //49062..49323
// 'L'; //49324..49895
// 'M'; //49896..50370
// 'N'; //50371..50613
// 'O'; //50614..50621
// 'P'; //50622..50905
// 'Q'; //50906..51386 // 'R'; //51387..51445
// 'S'; //51446..52217
// 'T'; //52218..52697
//没有U,V
// 'W'; //52698..52979
// 'X'; //52980..53640
// 'Y'; //53689..54480
// 'Z'; //54481..55289 // iCnChar match the constant
if ((iCnChar >= ) && (iCnChar <= ))
{
return "A";
}
if ((iCnChar >= ) && (iCnChar <= ))
{
return "B";
}
if ((iCnChar >= ) && (iCnChar <= ))
{
return "C";
}
if ((iCnChar >= ) && (iCnChar <= ))
{
return "D";
}
if ((iCnChar >= ) && (iCnChar <= ))
{
return "E";
}
if ((iCnChar >= ) && (iCnChar <= ))
{
return "F";
}
if ((iCnChar >= ) && (iCnChar <= ))
{
return "G";
}
if ((iCnChar >= ) && (iCnChar <= ))
{
return "H";
}
if ((iCnChar >= ) && (iCnChar <= ))
{
return "J";
}
if ((iCnChar >= ) && (iCnChar <= ))
{
return "K";
}
if ((iCnChar >= ) && (iCnChar <= ))
{
return "L";
}
if ((iCnChar >= ) && (iCnChar <= ))
{
return "M";
} if ((iCnChar >= ) && (iCnChar <= ))
{
return "N";
}
if ((iCnChar >= ) && (iCnChar <= ))
{
return "O";
}
if ((iCnChar >= ) && (iCnChar <= ))
{
return "P";
}
if ((iCnChar >= ) && (iCnChar <= ))
{
return "Q";
}
if ((iCnChar >= ) && (iCnChar <= ))
{
return "R";
}
if ((iCnChar >= ) && (iCnChar <= ))
{
return "S";
}
if ((iCnChar >= ) && (iCnChar <= ))
{
return "T";
}
if ((iCnChar >= ) && (iCnChar <= ))
{
return "W";
}
if ((iCnChar >= ) && (iCnChar <= ))
{
return "X";
}
if ((iCnChar >= ) && (iCnChar <= ))
{
return "Y";
}
if ((iCnChar >= ) && (iCnChar <= ))
{
return "Z";
}
return ("?");
}
}
public class NameAndLetter
{
public string Name { get; set; }
public string Letter { get; set; }
}

以上就是这次使用的总结,记录下来为以后使用方便,也加深记忆:

全部代码:

using DevExpress.XtraBars;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms; namespace CreawayMeasureManageTool
{
public partial class RadialMenu : Form
{
DevExpress.XtraBars.Ribbon.RadialMenu radialMenu = new DevExpress.XtraBars.Ribbon.RadialMenu();
BarManager barManager = new BarManager();
public RadialMenu()
{
InitializeComponent();
this.Load += delegate
{
#region MyRegion
List<string> list = new List<string>();
for (int i = ; i <= ; i++)
{
list.Add("啊受命于天" + i);
}
for (int i = ; i <= ; i++)
{
list.Add("吧受命于天" + i);
}
for (int i = ; i <= ; i++)
{
list.Add("才受命于天" + i);
}
for (int i = ; i <= ; i++)
{
list.Add("的受命于天" + i);
}
for (int i = ; i <= ; i++)
{
list.Add("额受命于天" + i);
}
for (int i = ; i <= ; i++)
{
list.Add("飞受命于天" + i);
} for (int i = ; i <= ; i++)
{
list.Add("个受命于天" + i);
}
for (int i = ; i <= ; i++)
{
list.Add("好吧受命于天" + i);
}
for (int i = ; i <= ; i++)
{
list.Add("就才受命于天" + i);
}
for (int i = ; i <= ; i++)
{
list.Add("看的受命于天" + i);
}
for (int i = ; i <= ; i++)
{
list.Add("了额受命于天" + i);
}
for (int i = ; i <= ; i++)
{
list.Add("吗飞受命于天" + i);
} for (int i = ; i <= ; i++)
{
list.Add("你受命于天" + i);
}
for (int i = ; i <= ; i++)
{
list.Add("哦吧受命于天" + i);
}
for (int i = ; i <= ; i++)
{
list.Add("平才受命于天" + i);
}
for (int i = ; i <= ; i++)
{
list.Add("去的受命于天" + i);
}
for (int i = ; i <= ; i++)
{
list.Add("人额受命于天" + i);
}
for (int i = ; i <= ; i++)
{
list.Add("是飞受命于天" + i);
} for (int i = ; i <= ; i++)
{
list.Add("他才受命于天" + i);
}
for (int i = ; i <= ; i++)
{
list.Add("我的受命于天" + i);
}
for (int i = ; i <= ; i++)
{
list.Add("想受命于天" + i);
}
for (int i = ; i <= ; i++)
{
list.Add("一飞受命于天" + i);
}
for (int i = ; i <= ; i++)
{
list.Add("在飞受命于天" + i);
}
#endregion radialMenu.InitDate(barManager, , ItemClick, this);
radialMenu.AddSubItemAndItem("更多", list); //Dictionary<string, List<string>> dic = new Dictionary<string, List<string>>();
//for (int i = 0; i < 10; i++)
//{
// list.Clear();
// for (int j = 0; j <= i + 5; j++)
// {
// list.Add("受命于天" + j);
// }
// if (i % 5 == 0)
// list.Clear();
// dic["受命于天" + i] = new List<string>(list);
//}
//radialMenu.InitDate(barManager, 10, ItemClick, this);
//radialMenu.AddSubItemAndItem(dic);
};
}
private void ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
var btnItem = sender as BarManager;
if (btnItem != null)
{
string name = btnItem.PressedLink.Caption;
switch (name)
{
case "系统维护":
case "查询统计":
case "视频查看":
case "视频服务":
case "重新登录":
case "告警查询":
case "事件查看":
case "通讯状态查询":
case "告警提示开":
case "告警联动开":
case "告警提示关":
case "告警联动关":
case "告警联动配置":
case "设备联动配置":
case "入侵检测配置":
case "入所管理":
case "视频轮播方案":
case "站内图编辑":
case "钥匙箱变电站关联":
case "告警统计":
case "故障查询":
case "挂牌查询":
case "辅助设备统计":
case "入所查询":
case "日志查询":
case "退运查询":
case "登陆人员查询":
case "设备动环曲线":
case "设备铭牌查询":
MessageBox.Show(name);
break;
default: break;
}
}
this.radialMenu.Collapse(false, true);
}
private void RadialMenu_Click(object sender, EventArgs e)
{
radialMenu.ShowPopup(Cursor.Position, true);
} }
public class CNSpellTranslator
{
/// <summary>
/// 在指定的字符串列表CnStr中检索符合拼音索引字符串
/// </summary>
/// <param name="CnStr">汉字字符串</param>
/// <returns>相对应的汉语拼音首字母串</returns>
public static string GetSpellCode(string CnStr)
{
string strTemp = "";
int iLen = CnStr.Length;
int i = ; for (i = ; i <= iLen - ; i++)
{
strTemp += GetCharSpellCode(CnStr.Substring(i, ));
}
return strTemp;
} /// <summary>
/// 输入是字母还是汉字
/// </summary>
/// <param name="firstKey"></param>
/// <returns></returns>
public static bool IsChar(char firstKey)
{
if ((firstKey >= 'a' && firstKey <= 'z') || (firstKey >= 'A' && firstKey <= 'Z'))
{
return true;
}
return false;
} /// <summary>
/// 得到一个汉字的拼音第一个字母,如果是一个英文字母则直接返回大写字母
/// </summary>
/// <param name="cnChar">单个汉字</param>
/// <returns>单个大写字母</returns>
private static string GetCharSpellCode(string cnChar)
{
long iCnChar; byte[] ZW = Encoding.Default.GetBytes(cnChar); //如果是字母,则直接返回
if (ZW.Length == )
{
return cnChar.ToUpper();
}
// get the array of byte from the single char
int i1 = ZW[];
int i2 = ZW[];
iCnChar = i1 * + i2; //expresstion
//table of the constant list
// 'A'; //45217..45252
// 'B'; //45253..45760
// 'C'; //45761..46317
// 'D'; //46318..46825
// 'E'; //46826..47009
// 'F'; //47010..47296
// 'G'; //47297..47613 // 'H'; //47614..48118
// 'J'; //48119..49061
// 'K'; //49062..49323
// 'L'; //49324..49895
// 'M'; //49896..50370
// 'N'; //50371..50613
// 'O'; //50614..50621
// 'P'; //50622..50905
// 'Q'; //50906..51386 // 'R'; //51387..51445
// 'S'; //51446..52217
// 'T'; //52218..52697
//没有U,V
// 'W'; //52698..52979
// 'X'; //52980..53640
// 'Y'; //53689..54480
// 'Z'; //54481..55289 // iCnChar match the constant
if ((iCnChar >= ) && (iCnChar <= ))
{
return "A";
}
if ((iCnChar >= ) && (iCnChar <= ))
{
return "B";
}
if ((iCnChar >= ) && (iCnChar <= ))
{
return "C";
}
if ((iCnChar >= ) && (iCnChar <= ))
{
return "D";
}
if ((iCnChar >= ) && (iCnChar <= ))
{
return "E";
}
if ((iCnChar >= ) && (iCnChar <= ))
{
return "F";
}
if ((iCnChar >= ) && (iCnChar <= ))
{
return "G";
}
if ((iCnChar >= ) && (iCnChar <= ))
{
return "H";
}
if ((iCnChar >= ) && (iCnChar <= ))
{
return "J";
}
if ((iCnChar >= ) && (iCnChar <= ))
{
return "K";
}
if ((iCnChar >= ) && (iCnChar <= ))
{
return "L";
}
if ((iCnChar >= ) && (iCnChar <= ))
{
return "M";
} if ((iCnChar >= ) && (iCnChar <= ))
{
return "N";
}
if ((iCnChar >= ) && (iCnChar <= ))
{
return "O";
}
if ((iCnChar >= ) && (iCnChar <= ))
{
return "P";
}
if ((iCnChar >= ) && (iCnChar <= ))
{
return "Q";
}
if ((iCnChar >= ) && (iCnChar <= ))
{
return "R";
}
if ((iCnChar >= ) && (iCnChar <= ))
{
return "S";
}
if ((iCnChar >= ) && (iCnChar <= ))
{
return "T";
}
if ((iCnChar >= ) && (iCnChar <= ))
{
return "W";
}
if ((iCnChar >= ) && (iCnChar <= ))
{
return "X";
}
if ((iCnChar >= ) && (iCnChar <= ))
{
return "Y";
}
if ((iCnChar >= ) && (iCnChar <= ))
{
return "Z";
}
return ("?");
}
}
public class NameAndLetter
{
public string Name { get; set; }
public string Letter { get; set; }
}
struct ItemAndSubItem
{
int itemClass;
List<string> listItems;
List<string> listSubItems;
} public static class RadialMenuExpression
{
private static bool isInit = false;
private static int index = ;
private static int ItemCount = ;
private static DevExpress.XtraBars.Ribbon.RadialMenu radialMenu;
private static BarManager barManager;
private static Action<object, ItemClickEventArgs> itemClick;
/// <summary>
/// 初始化
/// </summary>
/// <param name="barManagerExpression">barManager</param>
/// <param name="itemCountExpression">显示个数</param>
/// <param name="itemClickExpression">点击事件</param>
/// <param name="fromExpression">所属窗体</param>
/// <returns></returns>
public static bool InitDate(this DevExpress.XtraBars.Ribbon.RadialMenu radialMenuExpression, BarManager barManagerExpression, int itemCountExpression, Action<object, ItemClickEventArgs> itemClickExpression, Control fromExpression)
{
if (radialMenuExpression == null || barManagerExpression == null || itemCountExpression <= || itemClickExpression == null)
return false;
radialMenu = radialMenuExpression;
barManager = barManagerExpression;
ItemCount = itemCountExpression;
itemClick = itemClickExpression;
InitRadialMenu(fromExpression);
isInit = true;
return true;
}
private static void InitRadialMenu(Control from)
{
//radialMenu = new DevExpress.XtraBars.Ribbon.RadialMenu();
radialMenu.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)()))), ((int)(((byte)()))), ((int)(((byte)()))));
radialMenu.MenuColor = System.Drawing.Color.Teal;
barManager = new BarManager();
barManager.Form = from;
DevExpress.XtraBars.BarDockControl barDockControlLeft = new BarDockControl();
DevExpress.XtraBars.BarDockControl barDockControlRight = new BarDockControl();
DevExpress.XtraBars.BarDockControl barDockControlBottom = new BarDockControl();
DevExpress.XtraBars.BarDockControl barDockControlTop = new BarDockControl(); barDockControlTop.CausesValidation = false;
barDockControlTop.Dock = System.Windows.Forms.DockStyle.Top;
barDockControlTop.Location = new System.Drawing.Point(, );
barDockControlTop.Size = new System.Drawing.Size(, ); barDockControlBottom.CausesValidation = false;
barDockControlBottom.Dock = System.Windows.Forms.DockStyle.Bottom;
barDockControlBottom.Location = new System.Drawing.Point(, );
barDockControlBottom.Size = new System.Drawing.Size(, ); barDockControlLeft.CausesValidation = false;
barDockControlLeft.Dock = System.Windows.Forms.DockStyle.Left;
barDockControlLeft.Location = new System.Drawing.Point(, );
barDockControlLeft.Size = new System.Drawing.Size(, ); barDockControlRight.CausesValidation = false;
barDockControlRight.Dock = System.Windows.Forms.DockStyle.Right;
barDockControlRight.Location = new System.Drawing.Point(, );
barDockControlRight.Size = new System.Drawing.Size(, );
barManager.DockControls.Add(barDockControlTop);
barManager.DockControls.Add(barDockControlBottom);
barManager.DockControls.Add(barDockControlLeft);
barManager.DockControls.Add(barDockControlRight);
radialMenu.Manager = barManager;
//this.barManager.MaxItemId = listName.Count;
}
/// <summary>
/// 初始化
/// </summary>
/// <param name="dic">BarSubItem的名称为dic中key的值,BarSubItem中BarButtonItem的名称为对应的dic中value</param>
/// <param name="itemClick">RadialMenu中BarButtonItem的单击事件</param>
public static void AddSubItemAndBarItem(this DevExpress.XtraBars.Ribbon.RadialMenu radialMenuExpression, Dictionary<string, List<string>> dic)
{
if (!isInit)
return;
BarSubItem subItem = null;
foreach (KeyValuePair<string, List<string>> item in dic)
{
subItem = SetSubItem(item.Key);
if (item.Value.Count <= )
{
AddItem(item.Key, itemClick);
continue;
}
else
AddSubItem(subItem);
List<string> listItemName = item.Value;//.ToList();
int count = ;
foreach (string Itemname in listItemName)
{
count++;
if (subItem == null)
AddItem(Itemname, itemClick);
else
SubItemAddItem(itemClick, Itemname, subItem);
if (count != && count % ItemCount == )
{
BarSubItem subItemTemo = SetSubItem("更多");
SubItemAddSubItem(subItem, subItemTemo);
subItem = subItemTemo;
}
}
}
}
private static BarSubItem SetSubItem(string name)
{
BarSubItem subItem = new BarSubItem();
subItem.Id = index++;
subItem.Caption = name;
subItem.ItemAppearance.Hovered.ForeColor = System.Drawing.Color.Black;
subItem.ItemAppearance.Hovered.Options.UseForeColor = true;
subItem.ItemInMenuAppearance.Hovered.BackColor = System.Drawing.Color.Yellow;
subItem.ItemInMenuAppearance.Hovered.ForeColor = System.Drawing.Color.Black;
subItem.ItemInMenuAppearance.Hovered.Options.UseBackColor = true;
subItem.ItemInMenuAppearance.Hovered.Options.UseForeColor = true;
subItem.ItemInMenuAppearance.Normal.ForeColor = System.Drawing.Color.Yellow;
subItem.ItemInMenuAppearance.Normal.Options.UseForeColor = true;
return subItem;
}
private static BarButtonItem GetBarButtonItem(string name, Action<object, ItemClickEventArgs> itemClick)
{
BarButtonItem item = new BarButtonItem();
item.Id = index++;
item.Caption = name;
item.ItemAppearance.Disabled.ForeColor = System.Drawing.Color.Yellow;
item.ItemAppearance.Disabled.Options.UseForeColor = true;
item.ItemInMenuAppearance.Hovered.BackColor = System.Drawing.Color.Yellow;
item.ItemInMenuAppearance.Hovered.Options.UseBackColor = true;
item.ItemInMenuAppearance.Hovered.Options.UseForeColor = true;
item.ItemInMenuAppearance.Normal.ForeColor = System.Drawing.Color.Yellow;
item.ItemInMenuAppearance.Normal.Options.UseForeColor = true;
item.Name = name;
item.ItemClick += new DevExpress.XtraBars.ItemClickEventHandler(itemClick);
return item;
}
/// <summary>
/// 正常初始化
/// </summary>
/// <param name="name">BarSubItem的名称</param>
/// <param name="listName">RadialMenu中BarButtonItem的名称</param>
/// <param name="itemClick">RadialMenu中BarButtonItem的单击事件</param>
public static void AddSubItemAndBarItem(this DevExpress.XtraBars.Ribbon.RadialMenu radialMenuExpression, string name, List<string> listName)
{
if (!isInit)
return;
BarSubItem subItem = null;
int count = ;
bool flag = false;
foreach (string Itemname in listName)
{
count++;
if (subItem == null)
AddItem(Itemname, itemClick);
else
SubItemAddItem(itemClick, Itemname, subItem);
if (count != && count % ItemCount == )
{
if (!flag)
{
subItem = SetSubItem(name);
AddSubItem(subItem);
flag = true;
}
else
{
BarSubItem subItemTemo = SetSubItem(name);
SubItemAddSubItem(subItem, subItemTemo);
subItem = subItemTemo;
}
count = ;
}
}
}
private static void AddSubItem(BarSubItem subItem)
{
radialMenu.BeginInit();
barManager.BeginInit();
radialMenu.LinksPersistInfo.Add(new LinkPersistInfo(subItem));
barManager.Items.Add(subItem);
radialMenu.EndInit();
barManager.EndInit();
}
private static void SubItemAddSubItem(BarSubItem subItem, BarSubItem addItem)
{
radialMenu.BeginInit();
barManager.BeginInit();
subItem.LinksPersistInfo.Add(new LinkPersistInfo(addItem));
barManager.Items.Add(addItem);
radialMenu.EndInit();
barManager.EndInit();
}
private static void AddItem(string nameItem, Action<object, ItemClickEventArgs> itemClick)
{
radialMenu.BeginInit();
barManager.BeginInit();
BarButtonItem item = GetBarButtonItem(nameItem, itemClick);
radialMenu.LinksPersistInfo.Add(new LinkPersistInfo(item));
barManager.Items.Add(item);
radialMenu.EndInit();
barManager.EndInit();
}
private static void SubItemAddItem(Action<object, ItemClickEventArgs> itemClick, string nameItem, BarSubItem subItem)
{
radialMenu.BeginInit();
barManager.BeginInit();
BarButtonItem item = GetBarButtonItem(nameItem, itemClick);
subItem.LinksPersistInfo.Add(new LinkPersistInfo(item));
barManager.Items.Add(item);
radialMenu.EndInit();
barManager.EndInit();
} /// <summary>
/// 按首字母进行初始化
/// </summary>
/// <param name="listName">RadialMenu中BarButtonItem的名称</param>
/// <param name="itemClick">RadialMenu中BarButtonItem的单击事件</param>
public static void AddSubItemAndBarItem(this DevExpress.XtraBars.Ribbon.RadialMenu radialMenuExpression, List<string> listName)
{
if (!isInit)
return;
List<NameAndLetter> listNameAndLetter = new List<NameAndLetter>();
Dictionary<string, List<NameAndLetter>> dic = new Dictionary<string, List<NameAndLetter>>();
foreach (string name in listName)
{
NameAndLetter item = new NameAndLetter();
item.Name = name;
item.Letter = CNSpellTranslator.GetSpellCode(name);
listNameAndLetter.Add(item);
}
List<string> list = listNameAndLetter.OrderBy(x => x.Letter.Substring(, )).Select(x => x.Letter.Substring(, )).Distinct().ToList();
foreach (string name in list)
{
dic[name] = listNameAndLetter.Where(x => x.Letter.Substring(, ) == name).ToList();
}
SetDictionary(dic);
BarSubItem subItem = null;
foreach (KeyValuePair<string, List<NameAndLetter>> item in dic)
{
subItem = SetSubItem(item.Key);
AddSubItem(subItem);
List<string> listItemName = item.Value.Select(x => x.Name).ToList();
int count = ;
foreach (string Itemname in listItemName)
{
count++;
if (subItem == null)
AddItem(Itemname, itemClick);
else
SubItemAddItem(itemClick, Itemname, subItem);
if (count != && count % ItemCount == )
{
BarSubItem subItemTemo = SetSubItem("更多");
SubItemAddSubItem(subItem, subItemTemo);
subItem = subItemTemo;
}
}
}
}
private static void SetDictionary(Dictionary<string, List<NameAndLetter>> dic, bool flagCount = true)
{
if (dic.Count < )
return;
Dictionary<string, List<NameAndLetter>> dicMin = GetMinDicOrMax(dic, true);
Dictionary<string, List<NameAndLetter>> dicMax = GetMinDicOrMax(dic, true);
string key = "";
List<NameAndLetter> value = new List<NameAndLetter>();
if (dicMax.Count <= && dicMin.Count <= )
return;
foreach (KeyValuePair<string, List<NameAndLetter>> item in dicMin)
{
key += item.Key;
value = value.Concat(item.Value).ToList();
}
foreach (KeyValuePair<string, List<NameAndLetter>> item in dicMax)
{
key += item.Key;
value = value.Concat(item.Value).ToList();
}
dic[key] = value;
if (dic.Count >= )
SetDictionary(dic);
}
private static Dictionary<string, List<NameAndLetter>> GetMinDicOrMax(Dictionary<string, List<NameAndLetter>> dic, bool
isMin)
{
Dictionary<string, List<NameAndLetter>> dicTemp = new Dictionary<string, List<NameAndLetter>>();
if (dic.Count <= )
return dicTemp;
int count = ;
bool flagMinDic = false; foreach (KeyValuePair<string, List<NameAndLetter>> item in dic)
{
int letterCount = item.Value.Count;
if (!flagMinDic)
{
count = item.Value.Count;
dicTemp[item.Key] = item.Value;
flagMinDic = true;
continue;
}
if (isMin)
{
if (letterCount < count)
{
dicTemp.Clear();
dicTemp[item.Key] = item.Value;
}
}
else
{
if (letterCount > count)
{
dicTemp.Clear();
dicTemp[item.Key] = item.Value;
}
}
}
foreach (KeyValuePair<string, List<NameAndLetter>> item in dicTemp)
{
dic.Remove(item.Key);
}
return dicTemp;
} }
}

Devexpress 中对RedailMenu的使用的更多相关文章

  1. [转]''\\=DevExpress 中 汉化包 汉化方法

    [DevExpress]DevExpress 中 汉化包 汉化方法 2016-02-17 21:13 1781人阅读 评论(0) 收藏 举报  分类: DevExpress(24)  版权声明:本文为 ...

  2. DevExpress 中 在做全选的全消功能的时候 加快效率

    在做 DevExpress 中对增加的选择 Check列 控制全选的全消时通过以下代码红色字代码效率会有明显的提升: private void CheckedRow() { try { splashS ...

  3. devexpress中gridcontrol头部添加垂直线(右边框)

    winform开发,用devexpress中的gridcontrol控件,头部默认是3D样式,当客户希望像内容一样扁平化显示且需要添加垂直线(右边框)时恶梦开始了..经过一阵摸索发现可以这样解决: 1 ...

  4. devexpress中gridview控件编辑时改变输入法状态

    在win7环境下使用Devexpress中的SpinEdit控件,切换成中文[简/繁]输入法输入数字键时有不少输入法会重复产生数字如输入1会变成11,输入123会变成112233.使用SpinEdit ...

  5. DevExpress中,添加Winform窗体到DockPanel z

    DevExpress中,添加Winform窗体到DockPanel // 在使用DevExpress过程中,原先已经创建好的导航窗体,如何添加到DockPanel中进行展示? FormX frmX = ...

  6. 使用Devexpress中的CharControl控件,需要控制AxisY轴的显示范围,需要使用该控件的BoundDataChanged事件

    一.控制ChartControl的Y轴范围 使用Devexpress中的CharControl控件,需要控制AxisY轴的显示范围,需要使用该控件的BoundDataChanged事件,具体代码如下: ...

  7. DevExpress中GridView Excel下载

    DevExpress中GridView提供了许多Excel下载的方法,如gridView.ExportToExcelOld(sfdExcelDown.FileName); 在修改Bug时,遇到这样问题 ...

  8. DevExpress中RibbonControl的简单应用

    现在介绍一下DevExpress中的RibbonControl的简单应用,搭建一个拥有Office2010风格的窗体程序. 第一步:打开VS2015,新建一个windows窗体应用程序: 第二步:把需 ...

  9. 玩转控件:重绘DEVEXPRESS中DateEdit控件 —— 让DateEdit支持只选择年月 (提供源码下载)

      前言 上一篇博文<玩转控件:重绘ComboBox —— 让ComboBox多列显示>中,根据大家的回馈,ComboBox已经支持筛选了,更新见博文最后最后最后面.   奇葩 这两天遇到 ...

随机推荐

  1. NDK 开发(Android.mk配置)

         在我写这篇文章的时候,Android Studio已经是2.3版本了,已经集成CMake 编译工具, 用户只需在 新建项目的时候,添加选项(Include C++ support),Andr ...

  2. 每天一个Linux命令 4

    Linux系统关机命令 shutdown -h 时间 init 0 poweroff Linux系统注销命令 logout 或者是快捷键 Ctrl+d Linux系统重启命令 reboot Linux ...

  3. OpenvSwitch Port Mirror in OpenStack Neutron

    前言 最近使用搭建了一个基于VXLAN的OpenStack 环境,发现要去dump ovs interfaces的包其实还是蛮麻烦的, 经过多番努力,找到了如下的在openstack下网络环境的一些t ...

  4. JavaScript数据结构——队列的实现

    前面楼主简单介绍了JavaScript数据结构栈的实现,http://www.cnblogs.com/qq503665965/p/6537894.html,本次将介绍队列的实现. 队列是一种特殊的线性 ...

  5. android 透明状态栏方法及其适配键盘上推(二)

    在上一篇文章中介绍了一种设置透明状态栏及其适配键盘上推得方法.但是上一篇介绍的方法中有个缺点,就是不能消除掉statusbar的阴影.很多手机如(三星,Nexus都带有阴影).即使我用了: <a ...

  6. 关于css+div布局的疑问 2017-03-19

    第一次布局一个静态网页,发现许多细节都需要自己探索,出现诸如以下问题: 1.布局问题:经常出现一个div被挤出来?做到一半少一个div布局? 布局之前,要点打好框架,明确每个地方的高宽是多少,争取精确 ...

  7. 老司机实战Windows Server Docker:2 docker化现有iis应用的正确姿势

    前言 上一篇老司机实战Windows Server Docker:1 初体验之各种填坑介绍了安装docker服务过程中的一些小坑.这一篇,我们来填一些稍大一些的坑:如何docker化一个现有的iis应 ...

  8. Exchange Server 2007的即将生命周期,您的计划是?

    多数人做微软技术,Exchange Server 几乎所有 Microsoft 产品,都具有产品支持生命周期,原厂提供的新增功能. 错误修复.安全修补程序等.产品生命周期通常持续时间 10 年,超过期 ...

  9. 关于npm安装全局模块,require时报Error: Cannot find module 'XXX'的解决办法

    系统环境:centos 下午使用npm安装"cheerio",想搞爬虫玩玩. npm安装有两种模式: 本地 # npm install cheerio 全局 # npm insta ...

  10. IOS各种手势操作实例

    先看下效果 手势相关的介绍 IOS中手势操作一般是 UIGestureRecognizer 类的几个手势子类去实现,一般我们用到的手势就这么5种: 1.点击  UITapGestureRecogniz ...