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

2016-02-19 12:14 59 1 收藏

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

【 tulaoshi.com - 编程语言 】

最近谈论较多的就是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(重点介绍内容):

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

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

    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://www.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

来源:http://www.tulaoshi.com/n/20160219/1600312.html

延伸阅读
标签: Delphi
  Delphi关键字导航 网络 界面 多媒体 数据库 图像 控件 文件 硬件  在做Mis项目过程中,有时需要让用户自己来实现窗体控件的布局,比如酒店管理中就需要对餐厅餐桌位置进行布局。要实现这种功能,必须做好三件事: 1、设置进入控件边缘的光标形状; 2、改变控件的大小及位置; 3、保存窗体控件的位置及状态,窗体下次启动时...
标签: Web开发
代码如下: !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" html xmlns="http://www.w3.org/1999/xhtml" head titlejquery分页控件/title script src="jquery-1.3.min.js" type="text/javascript"/script /head body div class="pager"/div !--div s...
Delphi的IDE是本身就是一个非常精彩的软件,其中涵含了许多非常宝贵的软件知识。IDE中有一个窗体设计器,控件放在里面,就可以随意移动,以及调整大小,如果能够自己实现一个类似于这样的窗体设计器,那真是一件非常美妙事情。本文实现的就是窗体设计器中最重要的部分,一个移动控件的类,控件要求从TControl继承下来,在介绍如何实现之前,先说...
VC++中轻松实现滑动控件 作者: 上海同济大学计算机系 小鹰 下载本文示例代码 滑动控件是Windows中最常用的控件之一。一般而言它是由一个滑动条,一个滑块和可选的刻度组成,用户可以通过移动滑块在相应的控件中显示对应的值。通常,在滑动控件附近一定有标签控件或编辑框控件,用...
1,android:orientation 布局方向。horizontal是让所有的子元素按水平方向从左到右排列, vertical是让所有的子元素按竖直方向从上到下排列。 2,android:gravity 与 android:layout_gravity的区别android:gravity是指定本元素的子元素相对它的对齐方式。 android:layout_gravity是指定本元素相对它的父元素的对齐方式。 例如: 下面这里...

经验教程

435

收藏

65
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部