Public Class ThumbPanel
Inherits System.Windows.Forms.UserControl
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'UserControl1 overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents pnl As System.Windows.Forms.Panel
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.pnl = New System.Windows.Forms.Panel
Me.SuspendLayout()
'
'pnl
'
Me.pnl.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
Me.pnl.AutoScroll = True
Me.pnl.Location = New System.Drawing.Point(0, 0)
Me.pnl.Name = "pnl"
Me.pnl.Size = New System.Drawing.Size(496, 152)
Me.pnl.TabIndex = 0
'
'ThumbPanel
'
Me.Controls.Add(Me.pnl)
Me.Name = "ThumbPanel"
Me.Size = New System.Drawing.Size(232, 152)
Me.ResumeLayout(False)
End Sub
#End Region
Public Event Thumbnail_SingleClicked(ByRef ctrlControl As Control)
Public Event Thumbnail_DoubleClicked(ByRef ctrlControl As Control)
'Properties
'Thumbnail Properties
Private m_ThumbMaxWidth As Long
Private m_ThumbMaxHeight As Long
'Spacing Settings
Private m_ThumbSpaceWidth As Long ' How much distance between Thumbnails
Private m_ThumbSpaceHeight As Long ' how much distance between Rows
Public Property MaxThumbnailWidth() As Long
Get
Return m_ThumbMaxWidth
End Get
Set(ByVal Value As Long)
m_ThumbMaxWidth = Value
End Set
End Property
Public Property MaxThumbnailHeight() As Long
Get
Return m_ThumbMaxHeight
End Get
Set(ByVal Value As Long)
m_ThumbMaxHeight = Value
End Set
End Property
Public Property ThumbSpaceWidth() As Long
Get
Return m_ThumbSpaceWidth
End Get
Set(ByVal Value As Long)
m_ThumbSpaceWidth = Value
End Set
End Property
Public Property ThumbSpaceHeight() As Long
Get
Return m_ThumbSpaceHeight
End Get
Set(ByVal Value As Long)
m_ThumbSpaceHeight = Value
End Set
End Property
'Methods
Public Function AddImage(ByRef imgImage As Image) As Long
'Returns ControlID
Dim Thumb As New cThumbnail
With Thumb
.MaxThumbnailHeight() = m_ThumbMaxHeight
.MaxThumbnailWidth() = m_ThumbMaxWidth
.SourceImage() = imgImage
.GenerateThumbnail()
pnl.Controls.Add(GetPictureBox(.ThumbnailImage))
CType(pnl.Controls.Item(pnl.Controls.Count - 1), Windows.Forms.PictureBox).Image = .ThumbnailImage
pnl.Controls.Item(pnl.Controls.Count - 1).Update()
End With
End Function
Private Function GetPictureBox(ByRef imgImage As Image) As PictureBox
Dim pic As New PictureBox
With pic
.BorderStyle = BorderStyle.FixedSingle
.SizeMode = PictureBoxSizeMode.CenterImage
.Height = m_ThumbMaxHeight
.Width = m_ThumbMaxWidth
NewTopLeft(.Top, .Left)
.Image = imgImage
.Visible = True
End With
'Create Handlers
AddHandler pic.Click, New System.EventHandler(AddressOf SingleClicked)
AddHandler pic.DoubleClick, New System.EventHandler(AddressOf DoubleClicked)
Return pic
End Function
Private Function NewTopLeft(ByRef lngNewTop As Long, ByRef lngNewLeft As Long)
Dim ctrl As Control
If pnl.Controls.Count = 0 Then
'No pictures have been added yet!
lngNewTop = m_ThumbSpaceHeight
lngNewLeft = m_ThumbSpaceWidth
Exit Function
End If
ctrl = pnl.Controls.Item(Me.Controls.Count - 1)
lngNewTop = ctrl.Top + ctrl.Height + m_ThumbSpaceHeight
lngNewLeft = ctrl.Left + ctrl.Width + m_ThumbSpaceWidth
If pnl.Width < (lngNewLeft + m_ThumbMaxWidth) Then
'we need to go down and all the way to the left
'so the left is the easiest
lngNewLeft = m_ThumbSpaceWidth
lngNewTop = lngNewTop + m_ThumbMaxHeight + m_ThumbMaxHeight
End If
End Function
Public Function ClearAll()
pnl.Controls.Clear()
End Function
'Picturebox Event Handlers
Private Sub SingleClicked(ByVal sender As Object, ByVal e As System.EventArgs)
RaiseEvent Thumbnail_SingleClicked(sender)
End Sub
Private Sub DoubleClicked(ByVal sender As Object, ByVal e As System.EventArgs)
RaiseEvent Thumbnail_DoubleClicked(sender)
End Sub
End Class