DevExpress是非常主流的.NET控件,目前全世界和中國都用很多用戶使用,不過由於是英文版,初次接觸的同學可能會覺得困難,這裡就總結DevExpress常見的10個使用技巧。
1.TextEditor(barEditItem)取文本
string editValue = barEditItem1.EditValue.ToString(); //錯誤,返回null
string editValue = ((DevExpress.XtraEditors.TextEdit)barEditItem).EditValue.ToString(); //精確,返回文本框內容 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控件
//添加Page
DevExpress.XtraBars.Ribbon.RibbonPage ribbonPage = new RibbonPage();
ribbonControl.Pages.Add(ribbonPage);
//添加Group
DevExpress.XtraBars.Ribbon.RibbonPageGroup ribbonPageGroup = new RibbonPageGroup();
ribbonPage.Groups.Add(ribbonPageGroup);
//添加Button
DevExpress.XtraBars.BarButtonItem barButtonItem = new BarButtonItem();
ribbonPageGroup.ItemLinks.Add(barButtonItem);
//添加barSubItem
DevExpress.XtraBars.BarSubItem barSubItem = new BarSubItem();
ribbonPageGroup.ItemLinks.Add(barSubItem);
//barSubItem下添加Button
barSubItem.AddItem(barButtonItem);
//奇異的刪除Page問題( DevExpress使用技巧)
while (this.ribbonControl.Pages.Count > 0)
{
ribbonControl.Pages.Remove(ribbonControl.Pages[0]); //調試正常,運轉報異常
}
while (this.ribbonControl.Pages.Count > 0)
{
ribbonControl.SelectedPage = ribbonControl.Pages[0];
ribbonControl.Pages.Remove(ribbonControl.SelectedPage); //運轉正常
}
//遏止F10鍵Tips (DevExpress使用技巧)
ribbonControl.Manager.UseF10KeyForMenu = false;
//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.BaseTabHitInfo 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 sender, 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.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"); //若皮膚稱號錯誤則按系統默許設置(第一個皮膚)
//GalleryFilterMenuPopup工作設置彈出選擇菜單的“All Groups”為中文
private void rgbiSkins_GalleryFilterMenuPopup(object sender, GalleryFilterMenuEventArgs e)
{
e.FilterMenu.ItemLinks[n].Caption = "一切皮膚"; //n=分組數+1
}
//GalleryInitDropDownGallery工作設置彈出皮膚列表的表頭“ALL Groups”為中文
private void rgbiSkins_GalleryInitDropDownGallery(object sender, InplaceGalleryEventArgs e)
{
e.PopupGallery.FilterCaption = "一切皮膚";
}
7.dockManager
將視圖的狀況信息保管到xml文件
dockManager1.SaveLayoutToXml("..\\UserConfig\\ViewInfo.xml");
導出xml中保管的狀況信息
dockManager1.RestoreLayoutFromXml("..\\UserConfig\\ViewInfo.xml");
8.barManager
設置bar的字體與系統字體
barAndDockingController1.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 == 5
{
TreeListNode node = treeList1.FindNodeByID(hi.Node.Id);
treeList1.FocusedNode = node;
this.popupMenu1.ShowPopup(MousePosition);
}
}
}
---------------------------------------------------
DevExpress DXperience 是.NET控件套包、IDE報表生成工具和企業應用程序框架,DXperience幫助中國軟件企業開發出很多優秀的軟件產品 DXperience其產品的品牌、質量,是全球公認的。