datagridprioritycolumn.vb

来自「TaskVision 应用程序展示了用于个人和公司相关任务管理的一个完整的 n 」· VB 代码 · 共 51 行

VB
51
字号
Imports System.IO

Public Class DataGridPriorityColumn
    Inherits System.Windows.Forms.DataGridTextBoxColumn

    Private m_HtImages As New Hashtable()
    Private Const c_PriorityImagesPath As String = "Images\"
    Private m_ResourceManager As New Resources.ResourceManager("TaskVision.Localize", System.Reflection.Assembly.GetExecutingAssembly())

    Public Sub New(ByVal headerText As String, ByVal mappingName As String, ByVal width As Integer)
        MyBase.HeaderText = headerText
        MyBase.MappingName = mappingName
        MyBase.Width = width
    End Sub

    Protected Overloads Overrides Sub Edit(ByVal source As System.Windows.Forms.CurrencyManager, ByVal rowNum As Integer, ByVal bounds As System.Drawing.Rectangle, ByVal isReadOnly As Boolean, ByVal instantText As String, ByVal cellIsVisible As Boolean)
        'do nothing
    End Sub

    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 backBrush As System.Drawing.Brush, ByVal foreBrush As System.Drawing.Brush, ByVal alignToRight As Boolean)
        Dim bVal As Object = GetColumnValueAtRow(source, rowNum)

        Dim imageToDraw As Image

        'we're caching the image in a hashtable
        If m_HtImages.ContainsKey(bVal) Then
            imageToDraw = CType(m_HtImages(bVal), System.Drawing.Image)
        Else
            'get the image from disk and cache it
            Try
                imageToDraw = Image.FromFile(c_PriorityImagesPath & CType(bVal, String) & ".gif")
                m_HtImages.Add(bVal, imageToDraw)
            Catch
                MessageBox.Show(m_ResourceManager.GetString("The_image_file") & " " & Application.StartupPath & "\" & c_PriorityImagesPath & CType(bVal, String) & m_ResourceManager.GetString("gif_was_not_found"), m_ResourceManager.GetString("File_Not_Found"))
                LogError.Write(m_ResourceManager.GetString("The_image_file") & " " & Application.StartupPath & "\" & c_PriorityImagesPath & CType(bVal, String) & m_ResourceManager.GetString("gif_was_not_found"))
                Return
            End Try
        End If


        'if the current row is this row, draw the selection back color
        If Me.DataGridTableStyle.DataGrid.CurrentRowIndex = rowNum Then
            g.FillRectangle(New SolidBrush(Me.DataGridTableStyle.SelectionBackColor), bounds)
        Else
            g.FillRectangle(backBrush, bounds)
        End If

        g.DrawImage(imageToDraw, New Point(bounds.X, bounds.Y))
    End Sub
End Class

⌨️ 快捷键说明

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