当前位置: 首页>>代码示例>>C#>>正文


C# TrackBar.ValueChanged事件代码示例

本文整理汇总了C#中System.Windows.Forms.TrackBar.ValueChanged事件的典型用法代码示例。如果您正苦于以下问题:C# TrackBar.ValueChanged事件的具体用法?C# TrackBar.ValueChanged怎么用?C# TrackBar.ValueChanged使用的例子?那么恭喜您, 这里精选的事件代码示例或许可以为您提供帮助。您也可以进一步了解该事件所在System.Windows.Forms.TrackBar的用法示例。


在下文中一共展示了TrackBar.ValueChanged事件的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: InitializeTrackBar

//Declare a new TrackBar object.
internal System.Windows.Forms.TrackBar TrackBar1;

// Initalize the TrackBar and add it to the form.
private void InitializeTrackBar()
{
    this.TrackBar1 = new System.Windows.Forms.TrackBar();
    TrackBar1.Location = new System.Drawing.Point(75, 30);

    // Set the TickStyle property so there are ticks on both sides
    // of the TrackBar.
    TrackBar1.TickStyle = TickStyle.Both;

    // Set the minimum and maximum number of ticks.
    TrackBar1.Minimum = 10;
    TrackBar1.Maximum = 100;

    // Set the tick frequency to one tick every ten units.
    TrackBar1.TickFrequency = 10;

    // Associate the event-handling method with the 
    // ValueChanged event.
    TrackBar1.ValueChanged += 
        new System.EventHandler(TrackBar1_ValueChanged);
    this.Controls.Add(this.TrackBar1);
}

// Handle the TrackBar.ValueChanged event by calculating a value for
// TextBox1 based on the TrackBar value.  
private void TrackBar1_ValueChanged(object sender, System.EventArgs e)
{
    TextBox1.Text = (System.Math.Round(TrackBar1.Value/10.0)).ToString();
}
开发者ID:.NET开发者,项目名称:System.Windows.Forms,代码行数:33,代码来源:TrackBar.ValueChanged

示例2: TrackBars

//引入命名空间
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(200, 200);
    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());
  }
}
开发者ID:C#程序员,项目名称:System.Windows.Forms,代码行数:79,代码来源:TrackBar.ValueChanged


注:本文中的System.Windows.Forms.TrackBar.ValueChanged事件示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。