看了下,有两种方案
1. 设置GcMultiRow的Enabled属性为False
代码如下,好处是比较简单就可以实现,但是缺点是Scrollbar不能滚动了
- this.gcMultiRow1.Enabled = false;
- this.gcMultiRow1.DefaultCellStyle.DisabledBackColor = Color.White;
- this.gcMultiRow1.DefaultCellStyle.DisabledForeColor = Color.Black;
复制代码
2. 重写WM_NCHITTEST消息
代码如下,好处是Scrollbar不影响ScrollBar是否可以点,可以精细控制不抢焦点的位置,缺点是代码有点复杂,需要把GcMultiRow控件派生一次。
-
- class MyGcMultiRow : GcMultiRow
- {
- public MyGcMultiRow()
- {
- }
- public const int WM_NCHITTEST = 0x0084;
- protected override void WndProc(ref Message m)
- {
- if (m.Msg == WM_NCHITTEST)
- {
- Point point = new Point(LowWord(m.LParam.ToInt32()), HighWord(m.LParam.ToInt32()));
- point = PointToClient(point);
- if (this.HitTest(point).Type != HitTestType.HorizontalScrollBar &&
- this.HitTest(point).Type != HitTestType.VerticalScrollBar)
- {
- return;
- }
- }
- base.WndProc(ref m);
- }
- public static ushort LowWord(int value)
- {
- return (ushort)(value & 0xffff);
- }
- public static ushort HighWord(int value)
- {
- return (ushort)((value & 0xffff0000) >> 16);
- }
- }
复制代码
希望对你有所帮助 |