TrackBar on value changed event handler : TrackBar « 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 » TrackBar 
23.21.1.TrackBar on value changed event handler
TrackBar on value changed event handler
using System;
using System.Drawing;
using System.Windows.Forms;

public class TrackBars : Form
{
  Panel pnl;
  PictureBox pb;
  TrackBar htbar;
  TrackBar vtbar;

  public TrackBars()
  {
    Size = new Size(500,520);

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

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

    pb = new PictureBox();
    pb.Parent = pnl;
    pb.Size = new Size(200200);
    pb.Location = new Point((pnl.Size.Width / 2(pb.Size.Width / 2),
                (pnl.Size.Height / 2(pb.Size.Height /2));
    pb.BorderStyle = BorderStyle.FixedSingle;
    pb.SizeMode = PictureBoxSizeMode.StretchImage;
    pb.Image = img;

    htbar = new TrackBar();
    htbar.Parent = this;
    htbar.Orientation = Orientation.Horizontal;
    htbar.Size = new Size(pnl.Width, 10);
    htbar.Location = new Point(pnl.Left, pnl.Bottom + 25);
    htbar.TickStyle = TickStyle.BottomRight;
    htbar.TickFrequency = 25;
    htbar.Minimum = 25;
    htbar.Maximum = 400;
    htbar.SmallChange = 10;
    htbar.LargeChange = 25;
    htbar.BackColor = Color.Yellow;
    htbar.Value = pb.Width;
    htbar.ValueChanged += new EventHandler(htbar_OnValueChanged);

    vtbar = new TrackBar();
    vtbar.Parent = this;
    vtbar.Orientation = Orientation.Vertical;
    vtbar.Size = new Size(25, pnl.Height);  
    vtbar.Location = new Point(pnl.Right + 25, pnl.Top);
    vtbar.TickStyle = TickStyle.Both;
    vtbar.SetRange(25,400);
    vtbar.SmallChange = 10;
    vtbar.LargeChange = 50;
    vtbar.TickFrequency = vtbar.Maximum / 20;
    vtbar.BackColor = Color.Pink;
    vtbar.Value = pb.Height;
    vtbar.ValueChanged += new EventHandler(vtbar_OnValueChanged);

  }

  private void htbar_OnValueChanged(object sender, EventArgs e)
  {
    pb.Size = new Size(htbar.Value, pb.Height);
  }

  private void vtbar_OnValueChanged(object sender, EventArgs e)
  {
    pb.Size = new Size(pb.Width, vtbar.Value);
  }

  static void Main() 
  {
    Application.Run(new TrackBars());
  }
}
23.21.TrackBar
23.21.1.TrackBar on value changed event handlerTrackBar on value changed event handler
23.21.2.TractBar Large/Small rangeTractBar Large/Small range
23.21.3.Color TrackerColor Tracker
23.21.4.TrackBar: SmallChange, LargeChange, Minimum, Maximum
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.