Use ScrollBar to control the image scroll in a PictureBox : ScrollBar « GUI « VB.Net Tutorial

VB.Net Tutorial
1. Language Basics
2. Data Type
3. Operator
4. Statements
5. Date Time
6. Class Module
7. Development
8. Collections
9. Generics
10. Attributes
11. Event
12. Stream File
13. GUI
14. GUI Applications
15. 2D Graphics
16. I18N Internationlization
17. Reflection
18. Regular Expressions
19. Security
20. Socket Network
21. Thread
22. Windows
23. XML
24. Database ADO.net
25. Design Patterns
Microsoft Office Word 2007 Tutorial
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial » GUI » ScrollBar 
13. 12. 4. Use ScrollBar to control the image scroll in a PictureBox
Use ScrollBar to control the image scroll in a PictureBox
 

Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms

public class UseScrollBarToControlTheScrollingOfAnImage
   public Shared Sub Main
        Application.Run(New Form1)
   End Sub
End class

Public Class Form1
    Inherits System.Windows.Forms.Form

#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

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is NothingThen
                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 PictureBox1 As System.Windows.Forms.PictureBox
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents HScrollBar1 As System.Windows.Forms.HScrollBar
    Friend WithEvents VScrollBar1 As System.Windows.Forms.VScrollBar
    Friend WithEvents Button1 As System.Windows.Forms.Button
    Friend WithEvents OpenFileDialog1 As System.Windows.Forms.OpenFileDialog
    <System.Diagnostics.DebuggerStepThrough()Private Sub InitializeComponent()
        Me.PictureBox1 = New System.Windows.Forms.PictureBox
        Me.Label1 = New System.Windows.Forms.Label
        Me.HScrollBar1 = New System.Windows.Forms.HScrollBar
        Me.VScrollBar1 = New System.Windows.Forms.VScrollBar
        Me.Button1 = New System.Windows.Forms.Button
        Me.OpenFileDialog1 = New System.Windows.Forms.OpenFileDialog
        Me.SuspendLayout()
        '
        'PictureBox1
        '
        Me.PictureBox1.Location = New System.Drawing.Point(6472)
        Me.PictureBox1.Name = "PictureBox1"
        Me.PictureBox1.Size = New System.Drawing.Size(168144)
        Me.PictureBox1.TabIndex = 0
        Me.PictureBox1.TabStop = False
        '
        'Label1
        '
        Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif"24.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label1.Location = New System.Drawing.Point(00)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(26448)
        Me.Label1.TabIndex = 1
        Me.Label1.Text = "Handling Images"
        '
        'HScrollBar1
        '
        Me.HScrollBar1.Location = New System.Drawing.Point(64200)
        Me.HScrollBar1.Name = "HScrollBar1"
        Me.HScrollBar1.Size = New System.Drawing.Size(16816)
        Me.HScrollBar1.TabIndex = 2
        Me.HScrollBar1.Visible = False
        '
        'VScrollBar1
        '
        Me.VScrollBar1.Location = New System.Drawing.Point(21672)
        Me.VScrollBar1.Name = "VScrollBar1"
        Me.VScrollBar1.Size = New System.Drawing.Size(16128)
        Me.VScrollBar1.TabIndex = 3
        Me.VScrollBar1.Visible = False
        '
        'Button1
        '
        Me.Button1.Location = New System.Drawing.Point(112248)
        Me.Button1.Name = "Button1"
        Me.Button1.TabIndex = 4
        Me.Button1.Text = "Load Image"
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(513)
        Me.ClientSize = New System.Drawing.Size(292273)
        Me.Controls.Add(Me.Button1)
        Me.Controls.Add(Me.VScrollBar1)
        Me.Controls.Add(Me.HScrollBar1)
        Me.Controls.Add(Me.Label1)
        Me.Controls.Add(Me.PictureBox1)
        Me.Name = "Form1"
        Me.Text = "Form1"
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgsHandles Button1.Click
         PictureBox1.Image = Image.FromFile("yourfile.jpg")
         HScrollBar1.Maximum = PictureBox1.Image.Width - PictureBox1.Width + HScrollBar1.Height
         VScrollBar1.Maximum = PictureBox1.Image.Height - PictureBox1.Height + VScrollBar1.Width

         VScrollBar1.Visible = True
         HScrollBar1.Visible = True

         If PictureBox1.Height > PictureBox1.Image.Height Then
             VScrollBar1.Visible = False
         End If

         If PictureBox1.Width > PictureBox1.Image.Width Then
             HScrollBar1.Visible = False
         End If
    End Sub

    Private Sub HScrollBar1_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgsHandles HScrollBar1.Scroll
        Dim gphPictureBox As Graphics = PictureBox1.CreateGraphics()
        gphPictureBox.DrawImage(PictureBox1.Image, New Rectangle(00, _
            PictureBox1.Width - HScrollBar1.Height, _
            PictureBox1.Height - VScrollBar1.Width), _
            New Rectangle(HScrollBar1.Value, VScrollBar1.Value, _
            PictureBox1.Width - HScrollBar1.Height, _
            PictureBox1.Height - VScrollBar1.Width), GraphicsUnit.Pixel)
    End Sub

    Private Sub VScrollBar1_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgsHandles VScrollBar1.Scroll
        Dim gphPictureBox As Graphics = PictureBox1.CreateGraphics()
        gphPictureBox.DrawImage(PictureBox1.Image, New Rectangle(00, _
            PictureBox1.Width - HScrollBar1.Height, _
            PictureBox1.Height - VScrollBar1.Width), _
            New Rectangle(HScrollBar1.Value, VScrollBar1.Value, _
            PictureBox1.Width - HScrollBar1.Height, _
            PictureBox1.Height - VScrollBar1.Width), GraphicsUnit.Pixel)
    End Sub
End Class

        
13. 12. ScrollBar
13. 12. 1. Scroll Bar scrolls and get its current valueScroll Bar scrolls and get its current value
13. 12. 2. Value change event: Verical/Horizontal scroll barValue change event: Verical/Horizontal scroll bar
13. 12. 3. Use ScollBar to control font sizeUse ScollBar to control font size
13. 12. 4. Use ScrollBar to control the image scroll in a PictureBoxUse ScrollBar to control the image scroll in a PictureBox
13. 12. 5. Use ScrollBars to control the scroll of an ImageUse ScrollBars to control the scroll of an Image
w_w__w_.j_a_va___2_s.___c__o___m__ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.