Imports System.Drawing
Imports System.Windows.Forms
Imports System.Windows.Forms.Control
Imports System.ComponentModel
Imports System.Text
Imports System.Collections
Imports System.Diagnostics
Imports BV.Core
Imports MidRange
Imports IMidRange
Imports GraphicsObjects
'Items de el Control ImageViewer
'Almacenan una imagen y una descripcion si esta disponible
'ademas de un objeto que es almacenado con la imagen
<CLSCompliant(True)> _
Public Class ImageItem
Inherits ItemBase
Private obj As Object
Private img As Image
Private intDescription As String
Protected intThumbSize As Size
Protected intAllowDeletions As Boolean
'Public Event UnSelectItem(ByVal sender As Object, ByVal e As EventArgs)
Sub New(ByVal ParentCtl As ImageViewer, ByVal objPtr As Object, ByVal newImage As Image, ByVal BorderRect As System.Drawing.Rectangle)
MyBase.New(ParentCtl)
obj = objPtr
img = newImage
intRect = BorderRect
intAllowDeletions = False
intThumbSize = ParentCtl.DefaultThumbSize
intBrushSelected.Color = Me.intParentControl.ForeColor
intPen.Color = Me.intParentControl.ForeColor
End Sub
#Region "Properties"
Public Property Image() As Image
Get
Return Me.img
End Get
Set(ByVal Value As Image)
img = Value
End Set
End Property
Public Property AllowDeletions() As Boolean
Get
Return intAllowDeletions
End Get
Set(ByVal Value As Boolean)
intAllowDeletions = Value
End Set
End Property
Public Property BordersRectangle() As System.Drawing.Rectangle
Get
Return intRect
End Get
Set(ByVal Value As System.Drawing.Rectangle)
intRect = Value
End Set
End Property
Public Property objPtr() As Object
Get
Return obj
End Get
Set(ByVal Value As Object)
obj = Value
End Set
End Property
#Region "Description"
Public Property Description() As String
Get
If (intDescription Is String.Empty Or intDescription Is Nothing) Then
If TypeOf obj Is IDescribible Then
Return CType(obj, IDescribible).Description 'sb.ToString
ElseIf TypeOf obj Is INameable Then
Return CType(obj, INameable).Name 'sb.ToString
Else
Return ""
End If
Else
Return intDescription
End If
End Get
Set(ByVal Value As String)
If Value Is Nothing Then
intDescription = ""
Else
intDescription = Value
End If
End Set
End Property
Public Property BriefDescription() As String
Get
If TypeOf obj Is IDescribible Then
Return CType(obj, IDescribible).BriefDescription
Else
Return intDescription
End If
End Get
Set(ByVal Value As String)
If Value Is Nothing Then
intDescription = ""
Else
intDescription = Value
End If
End Set
End Property
#End Region
Public Overrides ReadOnly Property Height() As Integer
Get
If Not intDescription Is Nothing Then
Return Me.intRect.Height + 2 + MessureString(intDescription).Height
ElseIf TypeOf obj Is INameable Then
Return Me.intRect.Height + 2 + MessureString(CType(obj, INameable).Name).Height
Else
Return Me.intRect.Height
End If
End Get
End Property
'devuelve las dimensiones de un string
Protected Function MessureString(ByVal str As String) As SizeF
Try
Dim g As Graphics
g = Me.intParentControl.CreateGraphics
MessureString = g.MeasureString(str, Me.intFont)
g.Dispose()
Catch ex As Exception
MessageManager.Send(Me, New MessageEventArgs("Excepci�n en " & Me.ToString & " MessureString", MessageEventArgs.EMessageType.Excepcion))
End Try
End Function
#End Region
Public Overrides Sub Redraw(ByVal sender As Object, ByVal p As PaintEventArgs)
Dim str As String = ""
p.Graphics.DrawImage(img, X, Y, intThumbSize.Width, intThumbSize.Height)
If Not intDescription Is Nothing Then
If Strings.Len(intDescription) > 8 Then
str = Strings.Left(intDescription, 6) & "..."
Else
str = intDescription
End If
ElseIf TypeOf obj Is INameable Then
If Strings.Len(CType(obj, INameable).Name) > 8 Then
str = Strings.Left(CType(obj, INameable).Name, 6) & "..."
Else
str = CType(obj, INameable).Name
End If
End If
p.Graphics.DrawString(str, Me.intFont, Me.intBrushText, X, Y + intThumbSize.Height + 2)
If intSelectObj.IsSelected Then
'agrega un rectangulo negro al seleccionado
p.Graphics.DrawRectangle(intPen, New System.Drawing.Rectangle(X - 1, _
Y - 1, _
intThumbSize.Width + 2, _
intThumbSize.Height + 2))
End If
End Sub
End Class