会员: 密码:  免费注册 | 忘记密码 | 会员登录 网页功能: 加入收藏 设为首页 网站搜索  
技术文档 > VB文档 > VB.Net
重写datagrid(禁止对列宽进行拖拽)
发表日期:2005-06-14 11:20:23作者:H 出处:CSDN  

Public Class notCResizegrid

    Inherits System.Windows.Forms.DataGrid

 

#Region \" Windows 窗体设计器生成的代码 \"

 

    Public Sub New()

        MyBase.New()

 

        \'该调用是 Windows 窗体设计器所必需的。

        InitializeComponent()

 

        \' InitializeComponent() 调用之后添加任何初始化

 

    End Sub

 

    \'UserControl 重写 dispose 以清理组件列表。

    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)

        If disposing Then

            If Not (components Is Nothing) Then

                components.Dispose()

            End If

        End If

        MyBase.Dispose(disposing)

    End Sub

 

    \'Windows 窗体设计器所必需的

    Private components As System.ComponentModel.IContainer

 

    \'注意:以下过程是 Windows 窗体设计器所必需的

    \'可以使用 Windows 窗体设计器修改此过程。

    \'不要使用代码编辑器修改它。

    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

        components = New System.ComponentModel.Container()

    End Sub

 

#End Region

 

    Protected Overrides Sub OnMouseDown(ByVal e As System.Windows.Forms.MouseEventArgs)

        Dim hti As System.Windows.Forms.DataGrid.HitTestInfo

        hti = Me.HitTest(e.X, e.Y)

        Select Case hti.Type

            Case DataGrid.HitTestType.ColumnResize

                Return

        End Select

        MyBase.OnMouseDown(e)

    End Sub

 

    Protected Overrides Sub OnMouseMove(ByVal e As System.Windows.Forms.MouseEventArgs)

        Dim hti As DataGrid.HitTestInfo = Me.HitTest(New Point(e.X, e.Y))

        \'如果鼠标事件类型为改变列宽则返回

        If hti.Type = DataGrid.HitTestType.ColumnResize Then

            Cursor.Current = Cursors.Default

            Return

        End If

        MyBase.OnMouseMove(e)

    End Sub

End Class

’////////////////////////////    闵峰

返回顶部】 【打印本页】 【关闭窗口

关于我们 / 给我留言 / 版权举报 / 意见建议 / 网站编程QQ群   
Copyright ©2003- 2024 Lihuasoft.net webmaster(at)lihuasoft.net 加载时间 0.0041