|
Imports System.Windows.Forms
Imports System.Drawing.Drawing2D
Imports System.Drawing
Imports System.Math
Public Class DataGridBmpColumn
Inherits DataGridColumnStyle
#Region "Deklarationen"
Private mBmpSizeF = New SizeF(33, 33)
Private mHorizontalAlignment As HorizontalAlignment = _
HorizontalAlignment.Center
Private mBackColorStart As Color = Color.White
Private mBackColorEnd As Color = Color.Black
Private mBackColorStyle As eBackColorStyle = _
eBackColorStyle.BackColorLinearGradientBrush
Private mLinearGradientMode As LinearGradientMode = _
LinearGradientMode.Vertical
Enum eBackColorStyle
BackColorAsTable
BackColorLinearGradientBrush
End Enum
#End Region
#Region "Property-Region"
Public Property BackColorLinearGradientMode() As _
LinearGradientMode
Get
Return mLinearGradientMode
End Get
Set(ByVal Value As LinearGradientMode)
mLinearGradientMode = Value
End Set
End Property
Public Property BackColorStyle() As eBackColorStyle
Get
Return mBackColorStyle
End Get
Set(ByVal Value As eBackColorStyle)
mBackColorStyle = Value
End Set
End Property
Public Property BmpSize() As SizeF
Get
Return mBmpSizeF
End Get
Set(ByVal Value As SizeF)
mBmpSizeF = Value
End Set
End Property
Public Property BackColorStart() As Color
Get
Return mBackColorStart
End Get
Set(ByVal Value As Color)
mBackColorStart = Value
End Set
End Property
Public Property BackColorEnd() As Color
Get
Return mBackColorEnd
End Get
Set(ByVal Value As Color)
mBackColorEnd = Value
End Set
End Property
Public Overrides Property Alignment() As HorizontalAlignment
Get
Return mHorizontalAlignment
End Get
Set(ByVal Value As System.Windows.Forms.HorizontalAlignment)
mHorizontalAlignment = Value
End Set
End Property
#End Region
#Region "Sonstige Funktionen und Subs"
Protected Overrides Function GetMinimumHeight() As Integer
Return mBmpSizeF.Height
End Function
Protected Overrides Function GetPreferredHeight(ByVal g As _
System.Drawing.Graphics, ByVal value As Object) As Integer
Return mBmpSizeF.Height
End Function
Protected Overrides Function GetPreferredSize(ByVal g As _
System.Drawing.Graphics, ByVal value As Object) As _
System.Drawing.Size
Return New Size(mBmpSizeF.Width, mBmpSizeF.Height)
End Function
Protected Overrides Function Commit(ByVal dataSource As _
System.Windows.Forms.CurrencyManager, _
ByVal rowNum As Integer) As Boolean
Return True
End Function
Protected Overrides Sub Abort(ByVal rowNum As Integer)
'ReadOnly
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)
'ReadOnly
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)
'ReadOnly
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)
'ReadOnly
End Sub
#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, _
ByVal backBrush As System.Drawing.Brush, _
ByVal foreBrush As System.Drawing.Brush, _
ByVal alignToRight As Boolean)
Try
If mBackColorStyle = _
eBackColorStyle.BackColorLinearGradientBrush Then
Dim newBrush = New LinearGradientBrush _
(New RectangleF(bounds.X, bounds.Y, bounds.Width, _
bounds.Height), mBackColorStart, mBackColorEnd, _
mLinearGradientMode)
g.FillRegion(newBrush, New Region(bounds))
Else
g.FillRegion(backBrush, New Region(bounds))
End If
Dim BitMapFileName As String = _
GetColumnValueAtRow(source, rowNum).ToString()
Dim newBitmap As Bitmap = New Bitmap(BitMapFileName)
Dim newHeight As Integer = _
Min(bounds.Height, mBmpSizeF.Height)
Dim newWidth As Integer = Min(bounds.Width, mBmpSizeF.Width)
Dim x As Integer = (bounds.Width / 2) - (mBmpSizeF.Width / 2)
Dim y As Integer = _
(bounds.Height / 2) - (mBmpSizeF.Height / 2)
If mHorizontalAlignment = HorizontalAlignment.Right Then
Dim rx As Integer = bounds.Width - mBmpSizeF.Width
bounds.Offset(rx, y)
ElseIf mHorizontalAlignment = HorizontalAlignment.Left Then
bounds.Offset(0, y)
Else
bounds.Offset(x, y)
End If
Dim newRectangle = _
New RectangleF(bounds.X, bounds.Y, newWidth, newHeight)
g.DrawImage(newBitmap, newRectangle)
Catch ex As Exception
Throw ex
End Try
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 alignToRight As Boolean)
Try
Dim BitMapFileName As String = _
GetColumnValueAtRow(source, rowNum).ToString()
Dim newBitmap As Bitmap = New Bitmap(BitMapFileName)
g.DrawImage(newBitmap, bounds)
Catch ex As Exception
Throw ex
End Try
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)
Paint(g, bounds, source, rowNum, False)
End Sub
#End Region
End Class
|
|