|
1.TextEditor(barEditItem)取文本
string editValue = barEditItem1.EditValue.ToString(); //错误,返回null
string editValue = ((DevExpress.XtraEditors.TextEdit)barEditItem).EditValue.ToString(); //正确,返回文本框内容
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问题
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
ribbonControl.Manager.UseF10KeyForMenu = false;
//DX按钮
ApplicationIcon属性改变图标
右键 Add ApplicationMenu 添加evExpress.XtraBars.Ribbon.ApplicationMenu
5.HitInfo
//在Tab页上点击右键的事件响应
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.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);
}
}
}
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);
}
}
}
treeList间的拖放,如从treeList1拖一个节点到treeList2上的一个节点上。
1.将treeList1的DragNodes属性设为true
treeList1.OptionsBehavior.DragNodes = true;
2.treeList2的事件处理:
private void treeList1_DragEnter(objectsender, DragEventArgs e)
{
e.Effect = DragDropEffects.Copy;
}
private void treeList1_DragDrop(objectsender, DragEventArgs e)
{
object obj = e.Data.GetData(typeof(TreeListNode));
DevExpress.XtraTreeList.TreeListHitInfo hi =treeList1.CalcHitInfo(treeList1.PointToClient(new Point(e.X, e.Y)));
TreeListNode newNode = treeList1.AppendNode(new object[] {((TreeListNode)obj).GetValue(this.treeListColumn1) }, hi.Node);
newNode.Tag = ((TreeListNode)obj).Tag;
}
private voidtreeListForm_CustomDrawNodeCell(object sender,DevExpress.XtraTreeList.CustomDrawNodeCellEventArgs e)
{
if(e.Node.Checked)
{
e.Appearance.Font= new Font(DevExpress.Utils.AppearanceObject.DefaultFont, FontStyle.Bold);
}
}
//勾选节点的限制
private voidtreeListGroup_BeforeCheckNode(object sender,DevExpress.XtraTreeList.CheckNodeEventArgs e)
{
if(e.Node.ImageIndex == USERICON)
{
e.CanCheck= false;
}
else
{
e.CanCheck= true;
//三种勾选状态只使用勾选/不勾选
e.State= (e.PrevState == CheckState.Checked ? CheckState.Unchecked :CheckState.Checked);
}
}
11.XtraTabControl
DevExpress.XtraTab.XtraTabControlxtraTabControl = new DevExpress.XtraTab.XtraTabControl();
//添加Tab
xtraTabControl.TabPages.Add("page1");
//清空TabPage
xtraTabControl.TabPages.Clear();
//设置TabPage不可见
xtraTabControl.TabPages[i].PageVisible =false;
//设置TabPage不可用
xtraTabControl.TabPages[i].PageEnable =false;
//设置TabPage下的控件不可用
xtraTabControl.TabPages.Controls[i].Enable= false;
12.RadioButton/CheckBox
DevExpress.XtraEditors.CheckEdit
//设置类型
Properties.CheckStyle = Standard/Radio/...
//设置一组单选按钮
Properties.RadioGroupIndex设置为同一个数字
13.ColorEdit
DevExpress.XtraEditors.ColorEdit
//设置是否显示系统颜色和Web颜色
Properties.ShowSystemColors = false;
Properties.ShowWebColors = false;
//取选中颜色值
Color color = int i = colorEdit1.Color;
//换算成int型,便于保存到文件
int i = colorEdit1.Color.ToArgb();
14.LayoutControl
//多个layoutcontrol选中后右键-Group可将所选控件置为一组
this.layoutControlGroup1.Expanded = true;//展开组,设为false为折叠组
this.layoutControlGroup1.ExpandButtonVisible= true;//使折叠按钮可见
this.layoutControlGroup1.ExpandOnDoubleClick= true;//双击展开、折叠组
//TextVisible属性设置Item前方的文字说明,一般设为false
15.GridControl
//绑定数据
protected override void InitMDBData(stringconnectionString)
{
DataSet ds = new DataSet();
System.Data.OleDb.OleDbDataAdapter oleDbDataAdapter = newSystem.Data.OleDb.OleDbDataAdapter("SELECT * FROM " + tblName,connectionString);
oleDbDataAdapter.Fill(ds, tblName);
gridControl1.DataSource = ds.Tables[tblName];
gridControl1.MainView.PopulateColumns();
}
//可以添加自定义EmbededNavigator的CustomButtons:
this.efDevGridOth.EmbeddedNavigator.Buttons.CustomButtons.AddRange(newNavigatorCustomButton[] {
new NavigatorCustomButton(5, "保存"),
new NavigatorCustomButton(6, "返回")
});
//设置Grid的Style,对应行的新增/修改状态:
private void gridView1_RowStyle(objectsender, RowStyleEventArgs e)
{
try
{
if(this.gridView1.DataRowCount < 1) return;
if(e.RowHandle < 0)
{
return;
}
if(((DataRowView)this.gridView1.GetRow(e.RowHandle)).Row.RowState ==DataRowState.Modified)
{
e.Appearance.Font = new Font(e.Appearance.Font, FontStyle.Bold);
}
if(((DataRowView)this.gridView1.GetRow(e.RowHandle)).Row.RowState ==DataRowState.Added)
{
e.Appearance.ForeColor = Color.Red;
}
}
catch (Exception ex)
{
this.EFMsgInfo = ex.Message;
}
}
16.LookUpEditor
//绑定数据
efDevLookUpEditType.Properties.DataSource =dataSet1.Tables[0]
efDevLookUpEditType.Properties.Columns.Add(newDevExpress.XtraEditors.Controls.LookUpColumnInfo("CODE"));
efDevLookUpEditType.Properties.Columns.Add(newDevExpress.XtraEditors.Controls.LookUpColumnInfo("CODE_DESC_1_CONTENT"));
efDevLookUpEditType.Properties.ValueMember= "CODE";
efDevLookUpEditType.Properties.DisplayMember= "CODE_DESC_1_CONTENT";
efDevLookUpEditType.EditValue =dataSet1.Tables[0].Rows[0]["CODE"];
|
评分
-
查看全部评分
|