Use ScrollBars to control the scroll of an Image : ScrollBar « GUI « VB.Net Tutorial

Home
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.LINQ
13.Stream File
14.GUI
15.GUI Applications
16.Windows Presentation Foundation
17.2D Graphics
18.I18N Internationlization
19.Reflection
20.Regular Expressions
21.Security
22.Socket Network
23.Thread
24.Windows
25.XML
26.Database ADO.net
27.Design Patterns
VB.Net
VB.Net by API
VB.Net Tutorial » GUI » ScrollBar 
14.12.5.Use ScrollBars to control the scroll of an Image
Use ScrollBars to control the scroll of an Image
imports System
imports System.Drawing
imports System.Windows.Forms

public class ScrollBars : inherits Form

  dim pnl as Panel
  dim pb as PictureBox
  dim hbar as HScrollBar
  dim vbar as VScrollBar
  dim img as Image

  public sub New()
    Size = new Size(480,300)

    img = Image.FromFile("yourfile.jpg")

    pnl = new Panel()
    pnl.Parent = me
    pnl.Size = new Size(400,200)
    pnl.Location = new Point(10,10)
    pnl.BorderStyle = BorderStyle.FixedSingle

    pb = new PictureBox()
    pb.Parent = pnl
    pb.Size = new Size(img.Size.Width, img.Size.Height)
    pb.Location = new Point(00)
    pb.SizeMode = PictureBoxSizeMode.CenterImage
    pb.Image = img

    hbar = new HScrollBar()
    hbar.Parent = me
    hbar.Location = new Point(pnl.Left, pnl.Bottom + 25)
    hbar.Size = new Size(pnl.Width, 25)
    hbar.Minimum = 0
    hbar.Maximum = 100
    hbar.SmallChange = 1
    hbar.LargeChange = 10
    hbar.Value = 10
    AddHandler hbar.ValueChanged, AddressOf hbar_OnValueChanged

    vbar = new VScrollBar()
    vbar.Parent = me
    vbar.Location = new Point(pnl.Right + 25, pnl.Top)
    vbar.Size = new Size(25, pnl.Height)
    vbar.Minimum = 0
    vbar.Maximum = 100
    vbar.SmallChange = 1
    vbar.LargeChange = 10
    vbar.Value = CType((vbar.Maximum - vbar.Minimum2, integer)
    AddHandler vbar.ValueChanged, AddressOf vbar_OnValueChanged
  end sub  '  close for constructor

  private sub hbar_OnValueChanged(ByVal sender as object,ByVal e as EventArgs)
    pb.Location = new Point(CType((pnl.Size.Width - img.Size.Width* _
      hbar.Value /(hbar.Maximum - hbar.LargeChange + 1), integer), _
      pb.Top)
  end sub

  private sub vbar_OnValueChanged(ByVal sender as object,ByVal e as EventArgs)
    pb.Location = new Point(pb.Left, _
      CType((pnl.Size.Height - img.Size.Height* _
      vbar.Value / (vbar.Maximum - vbar.LargeChange + 1), integer))
  end sub

  public shared sub Main() 
    Application.Run(new ScrollBars())
  end sub

end class
14.12.ScrollBar
14.12.1.Scroll Bar scrolls and get its current valueScroll Bar scrolls and get its current value
14.12.2.Value change event: Verical/Horizontal scroll barValue change event: Verical/Horizontal scroll bar
14.12.3.Use ScollBar to control font sizeUse ScollBar to control font size
14.12.4.Use ScrollBar to control the image scroll in a PictureBoxUse ScrollBar to control the image scroll in a PictureBox
14.12.5.Use ScrollBars to control the scroll of an ImageUse ScrollBars to control the scroll of an Image
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.