ScrollBar Value changed event handler : ScrollBar « GUI Windows Forms « C# / CSharp Tutorial

Home
C# / CSharp Tutorial
1.Language Basics
2.Data Type
3.Operator
4.Statement
5.String
6.struct
7.Class
8.Operator Overload
9.delegate
10.Attribute
11.Data Structure
12.Assembly
13.Date Time
14.Development
15.File Directory Stream
16.Preprocessing Directives
17.Regular Expression
18.Generic
19.Reflection
20.Thread
21.I18N Internationalization
22.LINQ
23.GUI Windows Forms
24.Windows Presentation Foundation
25.Windows Communication Foundation
26.Workflow
27.2D
28.Design Patterns
29.Windows
30.XML
31.XML LINQ
32.ADO.Net
33.Network
34.Directory Services
35.Security
36.unsafe
C# / C Sharp
C# / C Sharp by API
C# / CSharp Open Source
C# / CSharp Tutorial » GUI Windows Forms » ScrollBar 
23.24.2.ScrollBar Value changed event handler
ScrollBar Value changed event handler
using System;
using System.Drawing;
using System.Windows.Forms;

public class ScrollBarsControlPictureBox : Form
{
  Panel pnl;
  PictureBox pb;
  HScrollBar hbar;
  VScrollBar vbar;
  Image img;

  public ScrollBarsControlPictureBox()
  {
    Size = new Size(480,300);

    img = Image.FromFile("YourFile.gif");

    pnl = new Panel();
    pnl.Parent = this;
    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((pnl.Size.Width / 2(pb.Size.Width / 2),
                (pnl.Size.Height / 2(pb.Size.Height / 2));
    pb.SizeMode = PictureBoxSizeMode.CenterImage;
    pb.Image = img;

    hbar = new HScrollBar();
    hbar.Parent = this;
    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 = (hbar.Maximum - hbar.Minimum2;
    hbar.ValueChanged += new EventHandler(hbar_OnValueChanged);

    vbar = new VScrollBar();
    vbar.Parent = this;
    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 = (vbar.Maximum - vbar.Minimum2;
    vbar.ValueChanged += new EventHandler(vbar_OnValueChanged);

  }

  private void hbar_OnValueChanged(object sender, EventArgs e)
  {
    pb.Location = new Point((pnl.Size.Width - img.Size.Width(hbar.Value(hbar.Maximum - hbar.LargeChange + 1), pb.Top);
  }

  private void vbar_OnValueChanged(object sender, EventArgs e)
  {
    pb.Location = new Point(pb.Left, (pnl.Size.Height - img.Size.Height* vbar.Value / (vbar.Maximum - vbar.LargeChange + 1));
  }

  static void Main() 
  {
    Application.Run(new ScrollBarsControlPictureBox());
  }
}
23.24.ScrollBar
23.24.1.Use ScrollBar to control PictureUse ScrollBar to control Picture
23.24.2.ScrollBar Value changed event handlerScrollBar Value changed event handler
23.24.3.ScrollBar Large/Small RangeScrollBar Large/Small Range
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.