DataGridView.OnMouseClick(MouseEventArgs) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
引发 MouseClick 事件。
protected:
override void OnMouseClick(System::Windows::Forms::MouseEventArgs ^ e);
protected override void OnMouseClick(System.Windows.Forms.MouseEventArgs e);
override this.OnMouseClick : System.Windows.Forms.MouseEventArgs -> unit
Protected Overrides Sub OnMouseClick (e As MouseEventArgs)
参数
包含事件数据的 A MouseEventArgs 。
例外
控件配置为在收到焦点时进入编辑模式,但编辑单元格值的初始化失败,并且没有事件的处理程序 DataError 或处理程序已将 ThrowException 属性 true设置为 。 异常对象通常可强制转换为类型 FormatException。
示例
下面的代码示例演示如何使用此方法。
// Override OnMouseClick in a class derived from DataGridViewCell to
// enter edit mode when the user clicks the cell.
protected override void OnMouseClick(DataGridViewCellMouseEventArgs e)
{
if (base.DataGridView != null)
{
Point point1 = base.DataGridView.CurrentCellAddress;
if (point1.X == e.ColumnIndex &&
point1.Y == e.RowIndex &&
e.Button == MouseButtons.Left &&
base.DataGridView.EditMode !=
DataGridViewEditMode.EditProgrammatically)
{
base.DataGridView.BeginEdit(true);
}
}
}
' Override OnMouseClick in a class derived from DataGridViewCell to
' enter edit mode when the user clicks the cell.
Protected Overrides Sub OnMouseClick( _
ByVal e As DataGridViewCellMouseEventArgs)
If MyBase.DataGridView IsNot Nothing Then
Dim point1 As Point = MyBase.DataGridView.CurrentCellAddress
If point1.X = e.ColumnIndex And _
point1.Y = e.RowIndex And _
e.Button = MouseButtons.Left And _
Not MyBase.DataGridView.EditMode = _
DataGridViewEditMode.EditProgrammatically Then
MyBase.DataGridView.BeginEdit(True)
End If
End If
End Sub
注解
引发事件会通过委托调用事件处理程序。 有关详细信息,请参阅 处理和引发事件。
该方法 OnMouseClick 还允许派生类在不附加委托的情况下处理事件。 这是处理派生类中的事件的首选技术。
继承者说明
在派生类中重写 OnMouseClick(MouseEventArgs) 时,请务必调用基类的方法,以便已注册的 OnMouseClick(MouseEventArgs) 委托接收事件。