Imports System Imports System.Collections.Generic Imports System.Text Imports Xceed.Grid.Viewers Imports Xceed.Grid Imports System.Drawing Imports System.Drawing.Drawing2D Imports System.IO
Class PaintingViewer Inherits CellViewerManager
Shared Sub New() Dim stream As Stream = GetType(PaintingViewer).Assembly.GetManifestResourceStream("Xceed.Grid.Samples.Favorites.PNG")
' We clone the bitmap so that exceptions do not occur when the source stream is disposed of. Dim image As New Bitmap( New Bitmap( stream ), New Size( 16, 16 ) )
PaintingViewer.ValueImage = image
stream.Dispose() End Sub
Public Sub New() MyBase.New() End Sub
Protected Overrides Sub PaintCellBackground( ByVal cell As Cell, _ ByVal e As GridPaintEventArgs, _ ByRef handled As Boolean ) Dim quantity As Single = 0
If( ( Not cell.Value Is Nothing ) And ( Not cell.Value Is DBNull.Value ) And _ ( Not cell.Value Is cell.NullValue ) ) Then quantity = CType( Convert.ChangeType( cell.Value, GetType( Single ) ), Single ) End If
Dim x As Integer = e.DisplayRectangle.X Dim y As Integer = e.DisplayRectangle.Y + ( e.DisplayRectangle.Height - PaintingViewer.ValueImage.Height ) / 2
Dim imageHeight As Integer = PaintingViewer.ValueImage.Height Dim i As Integer
For i = 1 To quantity Step 1 e.Graphics.DrawImage( PaintingViewer.ValueImage, x, y ) x += PaintingViewer.ValueImage.Width Next i
' Notify the cell that its background has been painted by the CellViewerManager. handled = True End Sub
Protected Overrides Sub PaintCellForeground( ByVal cell As Cell, _ ByVal e As GridPaintEventArgs, ByRef handled As Boolean )
' Notify the cell that its foreground has been painted by the CellViewerManager. handled = True End Sub
Protected Overrides Function GetFittedHeightCore( ByVal cell As Cell, _ ByVal mode As AutoHeightMode, _ ByVal cellDisplayWidth As Integer, _ ByVal graphics As Graphics, _ ByVal printing As Boolean ) As Integer Return PaintingViewer.ValueImage.Height + 2 End Function
Private Shared ValueImage As Image End Class
|