0
回答
Wince系统下grid添加复选框问题
Imports System.Windows.Forms
Imports bwms_handy
Imports System.Reflection
Imports System.Drawing
Imports System.Globalization
Imports System.IO






Public Class DataGridCheckBoxColumn
    Inherits DataGridColumnStyle
    Private Parent As DataGrid
    Public Shared check As String = "image\checkbox.png"
    Public Shared uncheck As String = "image\uncheckbox.png"
    Dim exepath As String = IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetModules(0).FullyQualifiedName)


    Public Sub DataGridCheckBoxColumn(ByVal parent As DataGrid)
        parent = parent
    End Sub




    '=======================================================
    '   描述:   '实现checkbox效果
    '   创建人: hhe             创建日期:2016-12-14
    '   修改人:                   修改日期:
    '   备注:
    '   参数:g、bounds、source、rowNum、backBrush、alignToRight、foreBrush
    '   返回值:
    '=======================================================
    Protected Overrides Sub Paint(ByVal g As Graphics, ByVal bounds As Rectangle, ByVal source As CurrencyManager, ByVal rowNum As Integer, ByVal backBrush As Brush, ByVal foreBrush As Brush, ByVal alignToRight As Boolean)


        Try


            Dim cellValue As Object = Me.PropertyDescriptor.GetValue(source.List(rowNum)) '取得该列的值
            Dim images As Bitmap
            g.FillRectangle(backBrush, bounds)
            Dim tempSrc As Rectangle
            Dim x As Integer
            Dim y As Integer
            Dim asm As Assembly = Assembly.GetExecutingAssembly()
            Dim checkbox1 As Bitmap
            Dim checkbox2 As Bitmap
            checkbox1 = New Bitmap(IO.Path.Combine(exepath, check))
            checkbox2 = New Bitmap(IO.Path.Combine(exepath, uncheck))
            If (cellValue.Equals(DBNull.Value) Or Convert.ToBoolean(cellValue) = False) Then
                tempSrc = New Rectangle(0, 0, checkbox1.Width, checkbox1.Height)
                images = checkbox1
            Else
                tempSrc = New Rectangle(0, 0, checkbox2.Width, checkbox2.Height)
                images = checkbox2
            End If
            x = bounds.Left + (bounds.Width - tempSrc.Width) / 2 - 3
            y = bounds.Top + (bounds.Height - tempSrc.Height) / 2


            g.DrawImage(images, x, y)
        Catch ex As Exception


        End Try
    End Sub




End Class

<无标签>
举报
旧梦vs逆爱
发帖于2年前 0回/67阅
顶部