·天新网首页·加入收藏·设为首页
首页|笔记本|手机|数码相机|摄像机|MP3/MP4|主板|内存|显示器|办公|打印机|下载|开发|汽车|学院|业界
硬件|台式机|数码|数字家庭|投影仪|GPS/CPU|显卡|硬盘|服务器|网络|一体机|驱动|源码|游戏|考试|报价
您现在的位置:天新网 > 软件开发 > 开发文摘 > .Net文摘
重写datagrid(禁止对列宽进行拖拽)
http://dev.21tx.com 2005年05月28日 Blog HanMo

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

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

上一篇: [FxCop.设计规则]6. 避免使用输出参数
下一篇: 处理WinForm多线程程序时的陷阱

Google
 
热点文章
关于我们 | 联系我们 | 广告服务 | 工作机会 | 版权声明 | 欢迎投稿 | 网站地图
Copyright © 2000-2008 , www.21tx.com , All Rights Reserved .
晨新科技 版权所有 Created by TXSite.net