Saturday, 12 September 2015

Windows similar Image Viewer and Image Mover in VB.NET

Windows similar Image Viewer and Image Mover in VB.NET



Code:(path image in Form Load must be changed to folder containing pictures)

Public Class Form20
    Dim a, b As Integer
    Private m_PanStartPoint As New Point

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Panel1.AutoScroll = True
        pb1.SizeMode = PictureBoxSizeMode.AutoSize
        ListBox1.Items.Clear()
        Dim di As New IO.DirectoryInfo(pathimage)
        Dim diar1 As IO.FileInfo() = di.GetFiles()
        Dim dra As IO.FileInfo
        Dim count = 0
        For Each dra In diar1
            ListBox1.Items.Add(dra)
            count = count + 1
        Next
        TextBox1.Text = count
    End Sub

    Private Sub pb1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles pb1.MouseDown
        m_PanStartPoint = New Point(e.X, e.Y)
    End Sub

    Private Sub pb1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles pb1.MouseMove
        If e.Button = Windows.Forms.MouseButtons.Left Then
            'Here we get the change in coordinates.
            'We multiply it by -1 because of how the panels autoscroll works.
            Dim DeltaX As Integer = (m_PanStartPoint.X - e.X)
            Dim DeltaY As Integer = (m_PanStartPoint.Y - e.Y)
            'Set the new autoscroll position.
            'ALWAYS pass positive integers to the panels autoScrollPosition method
            Panel1.AutoScrollPosition = New Drawing.Point((DeltaX - Panel1.AutoScrollPosition.X), (DeltaY - Panel1.AutoScrollPosition.Y))
        End If
    End Sub

    Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
        pb1.ImageLocation = pathimage & "\" & ListBox1.Text
        PictureBox1.ImageLocation = pathimage & "\" & ListBox1.Text
    End Sub


  


    Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged
        PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
    End Sub

    Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton2.CheckedChanged
        PictureBox1.SizeMode = PictureBoxSizeMode.Zoom
    End Sub

    Private Sub RadioButton3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton3.CheckedChanged
        PictureBox1.SizeMode = PictureBoxSizeMode.CenterImage
    End Sub

    Private Sub RadioButton4_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton4.CheckedChanged
        PictureBox1.SizeMode = PictureBoxSizeMode.Normal
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        PictureBox1.Visible = True
        a = PictureBox1.Location.X
        b = PictureBox1.Location.Y
        pb1.Visible = False
        Panel1.Visible = False
        PictureBox1.Size = Panel1.Size
        PictureBox1.Location = Panel1.Location
        RadioButton1.Visible = True
        RadioButton2.Visible = True
        RadioButton3.Visible = True
        RadioButton4.Visible = True
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        pb1.Visible = True
        Panel1.Visible = True
        PictureBox1.Location = New Point(a, b)
        PictureBox1.Size = New Point(143, 12)
        PictureBox1.Visible = False
        RadioButton1.Visible = False
        RadioButton2.Visible = False
        RadioButton3.Visible = False
        RadioButton4.Visible = False
    End Sub
End Class

No comments:

Post a Comment