|
サンプル投下します。
using System;
using System.Windows.Forms;
class DataGridViewEx : DataGridView
{
protected override void WndProc(ref Message m) {
switch (m.Msg) {
case WM_LBUTTONDOWN:
WmLButtonDown(ref m);
break;
case WM_LBUTTONDBLCLK:
WmLButtonDblClk(ref m);
break;
default:
base.WndProc(ref m);
break;
}
}
private bool fireCellDoubleClickEx;
private HitTestInfo fireHitTest;
private void WmLButtonDown(ref Message m) {
int x = SignedLOWORD(m.LParam);
int y = SignedHIWORD(m.LParam);
fireHitTest = base.HitTest(x, y);
base.WndProc(ref m);
fireCellDoubleClickEx = false;
switch (fireHitTest.Type) {
case DataGridViewHitTestType.Cell:
// ヘッダ付近だとリサイズ操作になるので
if (Cursor != Cursors.SizeWE &&
Cursor != Cursors.SizeNS &&
CurrentCell.RowIndex == fireHitTest.RowIndex &&
CurrentCell.ColumnIndex == fireHitTest.ColumnIndex) {
fireCellDoubleClickEx = true;
}
break;
}
}
private void WmLButtonDblClk(ref Message m) {
base.WndProc(ref m);
if (fireCellDoubleClickEx) {
OnCellDoubleClickEx(new DataGridViewCellEventArgs(
fireHitTest.ColumnIndex, fireHitTest.RowIndex));
}
}
public event DataGridViewCellEventHandler CellDoubleClickEx;
protected virtual void OnCellDoubleClickEx(DataGridViewCellEventArgs e) {
if (CellDoubleClickEx != null) CellDoubleClickEx.Invoke(this, e);
}
private const int WM_LBUTTONDOWN = 0x201;
private const int WM_LBUTTONDBLCLK = 0x203;
private static int SignedHIWORD(IntPtr n) {
return SignedHIWORD(unchecked((int)(long)n));
}
private static int SignedLOWORD(IntPtr n) {
return SignedLOWORD(unchecked((int)(long)n));
}
private static int SignedHIWORD(int n) {
return (short)((n >> 16) & 0xffff);
}
private static int SignedLOWORD(int n) {
return (short)(n & 0xFFFF);
}
}
|