按钮列的应用
m_columnNum = colNum
m_Row = -1
Try
Dim strm As System.IO.Stream = Me.GetType().Assembly.GetManifestResourceStream("btnface.bmp")
m_Face = New Bitmap(strm)
strm = Me.GetType().Assembly.GetManifestResourceStream("btnpressed.bmp")
m_FacePressed = New Bitmap(strm)
Catch
End Try
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 [readOnly] As Boolean, ByVal instantText As String, ByVal cellIsVisible As Boolean)
End Sub
Public Sub HandleMouseUp(ByVal sender As Object, ByVal e As MouseEventArgs)
Dim dg As DataGrid = Me.DataGridTableStyle.DataGrid
Dim hti As DataGrid.HitTestInfo = dg.HitTest(New Point(e.X, e.Y))
Dim isClickInCell As Boolean = hti.Column = Me.m_columnNum
m_Row = -1
Dim rect As New Rectangle(0, 0, 0, 0)
If isClickInCell Then
rect = dg.GetCellBounds(hti.Row, hti.Column)
isClickInCell = e.X > rect.Right - Me.m_Face.Width
End If
If isClickInCell Then
Dim g As Graphics = Graphics.FromHwnd(dg.Handle)
g.DrawImage(Me.m_Face, rect.Right - Me.m_Face.Width, rect.Y)
g.Dispose()
RaiseEvent CellButtonClicked(Me, New DataGridCellButtonClickEventArgs(hti.Row, hti.Column))
End If
End Sub
Public Sub HandleMouseDown(ByVal sender As Object, ByVal e As MouseEventArgs)
Dim dg As DataGrid = Me.DataGridTableStyle.DataGrid
Dim hti As DataGrid.HitTestInfo = dg.HitTest(New Point(e.X, e.Y))
Dim isClickInCell As Boolean = hti.Column = Me.m_columnNum
Dim rect As New Rectangle(0, 0, 0, 0)
If isClickInCell Then
rect = dg.GetCellBounds(hti.Row, hti.Column)
isClickInCell = e.X > rect.Right - Me.m_Face.Width
End If
If isClickInCell Then
Dim g As Graphics = Graphics.FromHwnd(dg.Handle)
g.DrawImage(Me.m_FacePressed, rect.Right - Me.m_FacePressed.Width, rect.Y)
g.Dispose()
m_Row = hti.Row
End If
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 parent As DataGrid = Me.DataGridTableStyle.DataGrid
'如果该行是选中行 或者 当前单元格的行号=点击行的行号并且当前单元格的列号等于NEW的列号参数
Dim current As Boolean = parent.IsSelected(rowNum) Or (parent.CurrentRowIndex = rowNum And parent.CurrentCell.ColumnNumber = Me.m_columnNum)
Dim BackColor As Color
If current Then BackColor = parent.SelectionBackColor Else BackColor = parent.BackColor
Dim ForeColor As Color
If current Then ForeColor = parent.SelectionForeColor Else ForeColor = parent.ForeColor












文章评论
共有 0 位网友发表了评论 此处只显示部分留言 点击查看完整评论页面