dassoubarna

AuthorCodeImageGallery

Feb 29th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 2.99 KB | None | 0 0
  1. Public Class AuthorCodeImageGalleryVB
  2.     Dim CtrlWidth As Integer
  3.     Dim CtrlHeight As Integer
  4.     Dim PicWidth As Integer
  5.     Dim PicHeight As Integer
  6.     Dim XLocation As Integer
  7.     Dim YLocation As Integer
  8.  
  9.     Private Sub AuthorCodeImageGalleryVB_Resize(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Resize
  10.         CtrlHeight = Me.Height
  11.         CtrlWidth = Me.Width
  12.     End Sub
  13.     Private _Directory_Path As String
  14.     Public Property Directorypath() As String
  15.         Get
  16.             Return _Directory_Path
  17.         End Get
  18.         Set(ByVal value As String)
  19.  
  20.             _Directory_Path = value
  21.             XLocation = 25
  22.             YLocation = 25
  23.             PicWidth = 117
  24.             PicHeight = 109
  25.             CreateGallery()
  26.         End Set
  27.     End Property
  28.     Dim i As Integer = 0
  29.     Private Sub DrawPictureBox(ByVal _filename As String, ByVal _displayname As String)
  30.         Dim Pic1 As New PictureBox
  31.         Pic1.Location = New System.Drawing.Point(XLocation, YLocation)
  32.         XLocation = XLocation + PicWidth + 20
  33.         If XLocation + PicWidth >= CtrlWidth Then
  34.             XLocation = 25
  35.             YLocation = YLocation + PicHeight + 20
  36.         End If
  37.         Pic1.Name = "PictureBox" & i
  38.         i += 1
  39.         Pic1.Size = New System.Drawing.Size(PicWidth, PicHeight)
  40.         Pic1.TabIndex = 0
  41.         Pic1.TabStop = False
  42.         Pic1.BorderStyle = BorderStyle.Fixed3D
  43.         Me.ToolTip1.SetToolTip(Pic1, _displayname)
  44.         AddHandler Pic1.MouseEnter, AddressOf Pic1_MouseEnter
  45.         AddHandler Pic1.MouseLeave, AddressOf Pic1_MouseLeave
  46.         Me.Controls.Add(Pic1)
  47.         Pic1.Image = Image.FromFile(_filename)
  48.         Pic1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage
  49.     End Sub
  50.     Private Sub CreateGallery()
  51.         i = 0
  52.         RemoveControls()
  53.         If Directorypath IsNot Nothing Then
  54.             Dim di As New IO.DirectoryInfo(Directorypath)
  55.             Dim diar1 As IO.FileInfo() = di.GetFiles("*.jpg").Concat(di.GetFiles("*.bmp")).Concat(di.GetFiles("*.png")).Concat(di.GetFiles("*.gif")).ToArray
  56.             Dim dra As IO.FileInfo
  57.             For Each dra In diar1
  58.                 DrawPictureBox(dra.FullName, dra.Name)
  59.             Next
  60.         End If
  61.     End Sub
  62.  
  63.     Private Sub Pic1_MouseEnter(ByVal sender As System.Object, ByVal e As System.EventArgs)
  64.         Dim Pic As PictureBox
  65.         Pic = sender
  66.         Pic.BorderStyle = BorderStyle.FixedSingle
  67.     End Sub
  68.     Private Sub Pic1_MouseLeave(ByVal sender As System.Object, ByVal e As System.EventArgs)
  69.         Dim Pic As PictureBox
  70.         Pic = sender
  71.         Pic.BorderStyle = BorderStyle.Fixed3D
  72.     End Sub
  73.     Private Sub RemoveControls()
  74. Again:  For Each ctrl As Control In Me.Controls
  75.             If TypeOf (ctrl) Is PictureBox Then
  76.                 Me.Controls.Remove(ctrl)
  77.             End If
  78.         Next
  79.         If Me.Controls.Count > 0 Then
  80.             GoTo Again
  81.         End If
  82.     End Sub
  83. End Class
Add Comment
Please, Sign In to add comment