⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 axdatagrid.vb

📁 此控件为.Net下为DataGrid增加拖动列功能.
💻 VB
字号:
'Option Strict On
Imports System.ComponentModel
Public Class AxDataGrid
    Inherits System.Windows.Forms.Control
    Dim myAddVisible As Boolean = True
    Dim myModiyVisible As Boolean = True
    Dim myDelVisible As Boolean = True
    Dim myFindVisible As Boolean = True
    Dim myTabs As Short = 1
    Dim mySelTabID As Short
    Dim mySelTabName As String
    Dim mySelTabText As String
    Dim myTabPages As System.Windows.Forms.TabPage

#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 窗体设计器修改此过程。
    '不要使用代码编辑器修改它。
    Friend WithEvents ToolBar As System.Windows.Forms.ToolBar
    Friend WithEvents Tab1 As System.Windows.Forms.TabPage
    Friend WithEvents DataGrid As System.Windows.Forms.DataGrid
    Friend WithEvents tbAdd As System.Windows.Forms.ToolBarButton
    Friend WithEvents tbModiy As System.Windows.Forms.ToolBarButton
    Friend WithEvents tbDel As System.Windows.Forms.ToolBarButton
    Friend WithEvents tbFind As System.Windows.Forms.ToolBarButton
    Friend WithEvents TabControl As System.Windows.Forms.TabControl
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.ToolBar = New System.Windows.Forms.ToolBar
        Me.tbAdd = New System.Windows.Forms.ToolBarButton
        Me.tbModiy = New System.Windows.Forms.ToolBarButton
        Me.tbDel = New System.Windows.Forms.ToolBarButton
        Me.tbFind = New System.Windows.Forms.ToolBarButton
        Me.TabControl = New System.Windows.Forms.TabControl
        Me.Tab1 = New System.Windows.Forms.TabPage
        Me.DataGrid = New System.Windows.Forms.DataGrid
        Me.TabControl.SuspendLayout()
        Me.Tab1.SuspendLayout()
        CType(Me.DataGrid, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'ToolBar
        '
        Me.ToolBar.Buttons.AddRange(New System.Windows.Forms.ToolBarButton() {Me.tbAdd, Me.tbModiy, Me.tbDel, Me.tbFind})
        Me.ToolBar.ButtonSize = New System.Drawing.Size(90, 20)
        Me.ToolBar.Cursor = System.Windows.Forms.Cursors.Hand
        Me.ToolBar.DropDownArrows = True
        Me.ToolBar.Location = New System.Drawing.Point(0, 0)
        Me.ToolBar.Name = "ToolBar"
        Me.ToolBar.ShowToolTips = True
        Me.ToolBar.Size = New System.Drawing.Size(472, 28)
        Me.ToolBar.TabIndex = 0
        Me.ToolBar.TextAlign = System.Windows.Forms.ToolBarTextAlign.Right
        '
        'tbAdd
        '
        Me.tbAdd.Text = "添加(&A)"
        '
        'tbModiy
        '
        Me.tbModiy.Text = "修改(&M)"
        '
        'tbDel
        '
        Me.tbDel.Text = "删除(&D)"
        '
        'tbFind
        '
        Me.tbFind.Style = System.Windows.Forms.ToolBarButtonStyle.ToggleButton
        Me.tbFind.Text = "查找(&F)"
        '
        'TabControl
        '
        Me.TabControl.Controls.Add(Me.Tab1)
        Me.TabControl.Dock = System.Windows.Forms.DockStyle.Fill
        Me.TabControl.Location = New System.Drawing.Point(0, 28)
        Me.TabControl.Name = "TabControl"
        Me.TabControl.SelectedIndex = 0
        Me.TabControl.Size = New System.Drawing.Size(472, 372)
        Me.TabControl.TabIndex = 1
        '
        'Tab1
        '
        Me.Tab1.Controls.Add(Me.DataGrid)
        Me.Tab1.Location = New System.Drawing.Point(4, 21)
        Me.Tab1.Name = "Tab1"
        Me.Tab1.Size = New System.Drawing.Size(464, 347)
        Me.Tab1.TabIndex = 0
        Me.Tab1.Text = "表单"
        '
        'DataGrid
        '
        Me.DataGrid.DataMember = ""
        Me.DataGrid.Dock = System.Windows.Forms.DockStyle.Fill
        Me.DataGrid.HeaderForeColor = System.Drawing.SystemColors.ControlText
        Me.DataGrid.Location = New System.Drawing.Point(0, 0)
        Me.DataGrid.Name = "DataGrid"
        Me.DataGrid.Size = New System.Drawing.Size(464, 347)
        Me.DataGrid.TabIndex = 0
        '
        'AxDataGrid
        '
        Me.Controls.Add(Me.TabControl)
        Me.Controls.Add(Me.ToolBar)
        Me.Name = "AxDataGrid"
        Me.Size = New System.Drawing.Size(472, 400)
        Me.TabControl.ResumeLayout(False)
        Me.Tab1.ResumeLayout(False)
        CType(Me.DataGrid, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)

    End Sub

#End Region

    <DefaultValue(True), Description("返回/设置一个值,决定‘添加’按钮是否显示")> _
    Public Property AddVisible() As Boolean
        Get
            Return myAddVisible
        End Get
        Set(ByVal Value As Boolean)
            myAddVisible = Value
            ToolBar.Buttons(0).Visible = myAddVisible
        End Set
    End Property
    <DefaultValue(True), Description("返回/设置一个值,决定‘修改’按钮是否显示")> _
        Public Property ModiyVisible() As Boolean
        Get
            Return myModiyVisible
        End Get
        Set(ByVal Value As Boolean)
            myModiyVisible = Value
            ToolBar.Buttons(1).Visible = myModiyVisible
        End Set
    End Property
    <DefaultValue(True), Description("返回/设置一个值,决定‘删除’按钮是否显示")> _
        Public Property DelVisible() As Boolean
        Get
            Return myDelVisible
        End Get
        Set(ByVal Value As Boolean)
            myDelVisible = Value
            ToolBar.Buttons(2).Visible = myDelVisible
        End Set
    End Property
    <DefaultValue(True), Description("返回/设置一个值,决定‘查找’按钮是否显示")> _
    Public Property FindVisible() As Boolean
        Get
            Return myFindVisible
        End Get
        Set(ByVal Value As Boolean)
            myFindVisible = Value
            ToolBar.Buttons(3).Visible = myFindVisible
        End Set
    End Property
    <DefaultValue(1), Description("返回/设置选项卡数目。")> _
        Public Property Tabs() As Short
        Get
            Return myTabs
        End Get
        Set(ByVal Value As Short)
            myTabPages = New System.Windows.Forms.TabPage
            TabControl.TabPages.Clear()
            Dim i As Short
            For i = 1 To myTabs
                myTabPages.Text = "表单" & i
                myTabPages.Name = "表单" & i
                TabControl.TabPages.Add(myTabPages)
                i = i + 1
            Next
            myTabs = Value
        End Set
    End Property
    <Description("返回/设置选项卡名称。")> _
        Public Property TabName() As String
        Get
            Return mySelTabName
        End Get
        Set(ByVal Value As String)
            mySelTabName = Value
            TabControl.TabPages(mySelTabID).Text = mySelTabName
        End Set
    End Property
    <Description("返回/设置选项卡文本内容。")> _
        Public Property TabText() As String
        Get
            Return mySelTabText
        End Get
        Set(ByVal Value As String)
            mySelTabText = Value
            TabControl.TabPages(mySelTabID).Text = mySelTabText
        End Set
    End Property

    Private Sub TabControl_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TabControl.SelectedIndexChanged
        mySelTabName = TabControl.SelectedTab.Name
        mySelTabText = TabControl.SelectedTab.Text
        mySelTabID = TabControl.SelectedIndex
    End Sub

End Class

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -