代码:
using DevExpress.Utils.Paint;
public class CustomXPaint : XPaint
...{
public override void DrawFocusRectangle(Graphics g, Rectangle rect, Color foreColor, Color backColor)
...{
if (CanDraw(rect) == false)
return;
Brush brush = Brushes.Red; //红色外框
g.FillRectangle(brush, new Rectangle(rect.X, rect.Y, 1, rect.Height - 1)); // left
g.FillRectangle(brush, new Rectangle(rect.X, rect.Y, rect.Width - 1, 1)); // top
g.FillRectangle(brush, new Rectangle(rect.Right - 1, rect.Y, 1, rect.Height - 1)); // right
g.FillRectangle(brush, new Rectangle(rect.X, rect.Bottom - 1, rect.Width, 1)); // bottom
}
}
public partial class Form1 : Form
...{
构造函数#region 构造函数
public Form1()
...{
InitializeComponent();
}
#endregion
画面激活时#region 画面激活时
void Form1_Activated(object sender, EventArgs e)
...{
//设自定义边框
FieldInfo fi = typeof(XPaint).GetField("graphics", BindingFlags.Static | BindingFlags.NonPublic);
fi.SetValue(null, new CustomXPaint());
}
#endregion
画面非激活时#region 画面非激活时
void Form1_Deactivate(object sender, EventArgs e)
...{
//恢复原样
FieldInfo fi = typeof(XPaint).GetField("graphics", BindingFlags.Static | BindingFlags.NonPublic);
fi.SetValue(null, new XPaint());
}
#endregion
}
public class CustomXPaint : XPaint
...{
public override void DrawFocusRectangle(Graphics g, Rectangle rect, Color foreColor, Color backColor)
...{
if (CanDraw(rect) == false)
return;
Brush brush = Brushes.Red; //红色外框
g.FillRectangle(brush, new Rectangle(rect.X, rect.Y, 1, rect.Height - 1)); // left
g.FillRectangle(brush, new Rectangle(rect.X, rect.Y, rect.Width - 1, 1)); // top
g.FillRectangle(brush, new Rectangle(rect.Right - 1, rect.Y, 1, rect.Height - 1)); // right
g.FillRectangle(brush, new Rectangle(rect.X, rect.Bottom - 1, rect.Width, 1)); // bottom
}
}
public partial class Form1 : Form
...{
构造函数#region 构造函数
public Form1()
...{
InitializeComponent();
}
#endregion
画面激活时#region 画面激活时
void Form1_Activated(object sender, EventArgs e)
...{
//设自定义边框
FieldInfo fi = typeof(XPaint).GetField("graphics", BindingFlags.Static | BindingFlags.NonPublic);
fi.SetValue(null, new CustomXPaint());
}
#endregion
画面非激活时#region 画面非激活时
void Form1_Deactivate(object sender, EventArgs e)
...{
//恢复原样
FieldInfo fi = typeof(XPaint).GetField("graphics", BindingFlags.Static | BindingFlags.NonPublic);
fi.SetValue(null, new XPaint());
}
#endregion
}
如果是只读的查询表格,可以添加如下的代码:
画面加载时#region 画面加载时
private void FormProjectBrowser_Load(object sender, EventArgs e)
...{
gridView1.OptionsBehavior.Editable = false;
gridView1.OptionsCustomization.AllowFilter = false;
gridView1.OptionsSelection.EnableAppearanceFocusedRow = true;
gridView1.OptionsSelection.EnableAppearanceFocusedCell = false;
gridView1.FocusRectStyle = DrawFocusRectStyle.RowFocus;
gridView1.Appearance.FocusedRow.BackColor = Color.PowderBlue;
gridView1.Appearance.FocusedRow.ForeColor = Color.Red;
//gridView1.Appearance.FocusedRow.Font = new Font(gridView1.Appearance.FocusedRow.Font, FontStyle.Bold);
gridView1.Appearance.HideSelectionRow.Assign(gridView1.Appearance.FocusedRow);
//...
}
private void FormProjectBrowser_Load(object sender, EventArgs e)
...{
gridView1.OptionsBehavior.Editable = false;
gridView1.OptionsCustomization.AllowFilter = false;
gridView1.OptionsSelection.EnableAppearanceFocusedRow = true;
gridView1.OptionsSelection.EnableAppearanceFocusedCell = false;
gridView1.FocusRectStyle = DrawFocusRectStyle.RowFocus;
gridView1.Appearance.FocusedRow.BackColor = Color.PowderBlue;
gridView1.Appearance.FocusedRow.ForeColor = Color.Red;
//gridView1.Appearance.FocusedRow.Font = new Font(gridView1.Appearance.FocusedRow.Font, FontStyle.Bold);
gridView1.Appearance.HideSelectionRow.Assign(gridView1.Appearance.FocusedRow);
//...
}
达到行选择的效果。(效果图上传不了)