datagridcolumnstyle重写,实现插入不同控件列体验

香菜爷丶

香菜爷丶

2016-02-19 12:14

在这个颜值当道,屌丝闪边的时代,拼不过颜值拼内涵,只有知识丰富才能提升一个人的内在气质和修养,所谓人丑就要多学习,今天图老师给大家分享datagridcolumnstyle重写,实现插入不同控件列体验,希望可以对大家能有小小的帮助。

最近谈论较多的就是Datagrid,特别新手最是郁闷为何没有更好的控件,来满足自已的需求。
其实通过重写可以达到很多不同的功能体验,在这里我们仅仅讨论关于datagridcolumnstyle重写的问题
==========================================
Power by: landlordh
Datatime: 2005-08-04
转载请注明出处,谢谢
==========================================
1。重写TextBox:

Public Class XP_TextBox
    Inherits System.Windows.Forms.TextBox


#Region " Windows "

    Public Sub New()
        MyBase.New()

        InitializeComponent()


    End Sub


    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


    System.Diagnostics.DebuggerStepThrough() Private Sub InitializeComponent()
       
        TextBox
       
        Me.EnableContextMenu = True
        Me.EnablePaste = True
        Me.Name = "TextBox"

    End Sub

#End Region

#Region " Variables "

    Private m_EnPaste As Boolean = True
    Private m_EnContextMenu As Boolean = True

#End Region

#Region " Property "

    Property EnablePaste() As Boolean
        Get
            Return m_EnPaste
        End Get
        Set(ByVal Value As Boolean)
            m_EnPaste = Value
            Me.Invalidate()
        End Set
    End Property

    Property EnableContextMenu() As Boolean
        Get
            Return m_EnContextMenu
        End Get
        Set(ByVal Value As Boolean)
            m_EnContextMenu = Value
            Me.Invalidate()
        End Set
    End Property

#End Region

    Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
        Select Case m.Msg
            Case &H302 paste
                RaiseEvent PasteEvent()
                If Not m_EnPaste Then Return
            Case &H7B contextmenu
                If Not m_EnContextMenu Then Return
        End Select
        MyBase.WndProc(m)
    End Sub

    Public Event PasteEvent()

End Class

2。重写datagridcolumnstyle(重点介绍内容):

(本文来源于图老师网站,更多请访问http://m.tulaoshi.com/bianchengyuyan/)

Imports System.Drawing
Imports System.Windows.Forms

Public NotInheritable Class DataGridTextBoxColumnStyle
    Inherits System.Windows.Forms.DataGridColumnStyle

#Region "Declare Property"

    Private WithEvents m_TextBox As New Landlord.Component.XP_TextBox
    Private IsEditing As Boolean
    Private EditingRow As Integer = -1
    Private m_oldvalue As String

#End Region

#Region " windows "

    Sub New()
        Me.m_TextBox.Visible = False
    End Sub

    Public Sub New(ByVal Container As System.ComponentModel.IContainer)
        MyClass.New()

        Container.Add(Me)
    End Sub

    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

    Private components As System.ComponentModel.IContainer

    System.Diagnostics.DebuggerStepThrough() Private Sub InitializeComponent()
        components = New System.ComponentModel.Container
    End Sub

#End Region

#Region "Get Function"

    Protected Overrides Function GetMinimumHeight() As Integer
        Return m_TextBox.PreferredHeight + 2
    End Function

    Protected Overrides Function GetPreferredHeight(ByVal g As System.Drawing.Graphics, ByVal value As Object) As Integer
        Return m_TextBox.PreferredHeight + 2
    End Function

    Protected Overrides Function GetPreferredSize(ByVal g As System.Drawing.Graphics, ByVal value As Object) As System.Drawing.Size
        Return New Size(50, m_TextBox.PreferredHeight + 2)
    End Function

#End Region

#Region "Paint"

    Protected Overloads Overrides Sub Paint(ByVal g As System.Drawing.Graphics, ByVal bounds As System.Drawing.Rectangle, ByVal [source] As System.Windows.Forms.CurrencyManager, ByVal rowNum As Integer)
        Paint(g, bounds, [source], rowNum, False)
    End Sub

(本文来源于图老师网站,更多请访问http://m.tulaoshi.com/bianchengyuyan/)

    Protected Overloads Overrides Sub Paint(ByVal g As System.Drawing.Graphics, ByVal bounds As System.Drawing.Rectangle, ByVal [source] As System.Windows.Forms.CurrencyManager, ByVal rowNum As Integer, ByVal alignToRight As Boolean)
        Dim brush_for As Brush = New SolidBrush(Me.DataGridTableStyle.ForeColor)
        Dim brush_bak As Brush = New SolidBrush(Me.D

展开更多 50%)
分享

猜你喜欢

datagridcolumnstyle重写,实现插入不同控件列体验

编程语言 网络编程
datagridcolumnstyle重写,实现插入不同控件列体验

excel怎么插入日历控件

excel
excel怎么插入日历控件

s8lol主宰符文怎么配

英雄联盟 网络游戏
s8lol主宰符文怎么配

如何在DataGrid控件中隐藏列

ASP
如何在DataGrid控件中隐藏列

c# 重载WndProc实现重写“最小化”的实现方法

编程语言 网络编程
c# 重载WndProc实现重写“最小化”的实现方法

lol偷钱流符文搭配推荐

英雄联盟 网络游戏
lol偷钱流符文搭配推荐

excel如何批量插入行和列

电脑入门
excel如何批量插入行和列

repeater实现多列显示

Web开发
repeater实现多列显示

lolAD刺客新符文搭配推荐

英雄联盟
lolAD刺客新符文搭配推荐

html5中canvas学习笔记1-画板的尺寸与实际显示尺寸

html5中canvas学习笔记1-画板的尺寸与实际显示尺寸

跟踪与中间过程输出

跟踪与中间过程输出
下拉加载更多内容 ↓