《DevExpress的常用技巧总结》由会员分享,可在线阅读,更多相关《DevExpress的常用技巧总结(4页珍藏版)》请在金锄头文库上搜索。
1、DevExpress 的常用技巧总结DevExpress 是 DevExpress 公司出品,非常主流的.NET 控件,目前全世界和中国都用很多用户使用,不过由于是英文版,初次接触的同学可能会觉得困难,这里就总结 DevExpress常见的 10 个使用技巧。1.TextEditor(barEditItem)取文本 string editValue = barEditItem1.EditValue.ToString(); /错误,返回 nullstring editValue = (DevExpress.XtraEditors.TextEdit)barEditItem).EditValue.T
2、oString(); /精确,返回文本框内容 DevExpress 使用技巧2.ComboBoxEdit(barEditItem)添加 Item string item = comboboxItem1;(DevExpress.XtraEditors.Repository.RepositoryItemComboBox)this.barEditItem.Edit).Items.Add(item);3.ComboBoxEdit(barEditItem)取文本 string itemValue = this.barEditItem.EditValue.ToString();4.Ribbon 控件 /添
3、加 PageDevExpress.XtraBars.Ribbon.RibbonPage ribbonPage = new RibbonPage();ribbonControl.Pages.Add(ribbonPage);/添加 GroupDevExpress.XtraBars.Ribbon.RibbonPageGroup ribbonPageGroup = new RibbonPageGroup();ribbonPage.Groups.Add(ribbonPageGroup);/添加 ButtonDevExpress.XtraBars.BarButtonItem barButtonItem =
4、 new BarButtonItem();ribbonPageGroup.ItemLinks.Add(barButtonItem);/添加 barSubItemDevExpress.XtraBars.BarSubItem barSubItem = new BarSubItem();ribbonPageGroup.ItemLinks.Add(barSubItem);/barSubItem 下添加 ButtonbarSubItem.AddItem(barButtonItem); /奇异的删除 Page 问题( DevExpress 使用技巧)while (this.ribbonControl.Pa
5、ges.Count 0)ribbonControl.Pages.Remove(ribbonControl.Pages0); /调试正常,运转报异常while (this.ribbonControl.Pages.Count 0)ribbonControl.SelectedPage = ribbonControl.Pages0;ribbonControl.Pages.Remove(ribbonControl.SelectedPage); /运转正常/遏止 F10 键 Tips (DevExpress 使用技巧)ribbonControl.Manager.UseF10KeyForMenu = fal
6、se;/DX 按钮ApplicationIcon 属性改动图标右键 Add ApplicationMenu 添加evExpress.XtraBars.Ribbon.ApplicationMenu5.HitInfo /在 Tab 页上点击右键的工作响应(DevExpress 使用技巧)void xtraTabbedMdiManager_Event(object sender, MouseEventArgs e)if (e.Button = MouseButtons.Right & ActiveMdiChild != null)DevExpress.XtraTab.ViewInfo.BaseTab
7、HitInfo hInfo = xtraTabbedMdiManager.CalcHitInfo(e.Location);/右键点击位置:在 Page 上且不在封闭按钮内if (hInfo.IsValid & hInfo.Page != null & !hInfo.InPageCloseButton)this.popupMenu.ShowPopup(Control.MousePosition);/在鼠标位置弹出,而不是 e.Location/在 ribbon 上点击右键的工作响应private void ribbonControl1_ShowCustomizationMenu(object s
8、ender, RibbonCustomizationMenuEventArgs e)/禁掉原系统右键菜单e.ShowCustomizationMenu = false;/右键位置:在 barButtonItem 上if (e.HitInfo != null & e.HitInfo.InItem& e.HitInfo.Item.Item is BarButtonItem) this.popupMenu.ShowPopup(Control.MousePosition);/右键位置:在 barSubItem 中的 barButtonItem 上else if (e.Link != null & e.
9、Link.Item != null & e.Link.Item is BarButtonItem)this.popupMenu.ShowPopup(Control.MousePosition);6.皮肤 /添加皮肤轨范集后注册皮肤( DevExpress 使用技巧)DevExpress.UserSkins.OfficeSkins.Register();DevExpress.UserSkins.BonusSkins.Register();/设置皮肤DevExpress.LookAndFeel.UserLookAndFeel.Default.SetSkinStyle(Liquid Sky); /若
10、皮肤称号错误则按系统默许设置(第一个皮肤)/GalleryFilterMenuPopup 工作设置弹出选择菜单的“All Groups”为中文private void rgbiSkins_GalleryFilterMenuPopup(object sender, GalleryFilterMenuEventArgs e)e.FilterMenu.ItemLinksn.Caption = 一切皮肤; /n=分组数+1/GalleryInitDropDownGallery 工作设置弹出皮肤列表的表头“ALL Groups”为中文private void rgbiSkins_GalleryInitD
11、ropDownGallery(object sender, InplaceGalleryEventArgs e)e.PopupGallery.FilterCaption = 一切皮肤;7.dockManager 将视图的状况信息保管到 xml 文件dockManager1.SaveLayoutToXml(.UserConfigViewInfo.xml);导出 xml 中保管的状况信息dockManager1.RestoreLayoutFromXml(.UserConfigViewInfo.xml);8.barManager 设置 bar 的字体与系统字体barAndDockingControl
12、ler1.AppearancesBar.ItemsFont = new Font(this.Font.FontFamily, currentFontSize);9.设置系统字体 DevExpress.Utils.AppearanceObject.DefaultFont = new Font(this.Font.FontFamily, currentFontSize);10.treeView 为 tree 节点加右键菜单并选中该节点private void treeList1_MouseDown(object sender, MouseEventArgs e)if (e.Button = MouseButtons.Right)DevExpress.XtraTreeList.TreeListHitInfo hi = treeList1.CalcHitInfo(e.Location);if (hi.Node != null & hi.Node.ImageIndex = 5) /叶子节点的ImageIndex = 5TreeListNode node = treeList1.FindNodeByID(hi.Node.Id);treeList1.FocusedNode = node;this.popupMenu1.ShowPopup(MousePosition);