WINFORM vscrollbar 和 hscrollbar的一些重要属性说明

为了查一个滚动条如何使用查了N多的国内网站都没找到如何使用这个滚动条,有的给的还是错的,目前google出了 滚动条一些重要属性的说明:

原网址:http://www.informit.com/articles/article.aspx?p=101720&seqNum=24

国内网站不给力啊……

Using the HScrollBar and VScrollBar Controls

The HScrollBar and VScrollBar controls allow you to add scrolling capabilities to components that do not support scrolling by default. The controls are driven by several properties. The following list contains these properties and their meanings.

  1. Minimum The value of the control when the scroll thumb is at the left end of the HScrollBar or top of the VScrollBar.

  2. Maximum This is the largest possible value of the scroll bar. Note that the Value property of the scroll bar when the thumb is pulled all the way to the right for the HScrollBar or the bottom of the VScrollBar is not equal to the Maximum property. The Value property will be equal to this formula: MaximumLargeChange + 1.

  3. SmallChange Here's the increment value used when the user clicks one of the arrow buttons.

  4. LargeChange This is the increment value used when the user clicks the scroll bar control on either side of the scroll thumb.

  5. Value The current value of the scroll bar. This value represents the position of the top of the HScrollBar's scroll thumb and the left side of the VScrollBar's scroll thumb.

A ValueChanged event is fired when the Value property changes. Trap this event to perform some action, such as change the position of a control, when the scroll bar's value changes. The following code demonstrates how to handle the ValueChanges event:

C#
private void hScrollBar1_ValueChanged(object sender, System.EventArgs e) {
 this.label1.Text = string.Format("Scroll Bar Value: {0}",
     this.hScrollBar1.Value);
}
VB
Private Sub hScrollBar1_ValueChanged(object sender,
    System.EventArgs e) _Handles hScrollBar1.ValueChanged
 Me.label1.Text = string.Format("Scroll Bar Value: {0}",
     this.hScrollBar1.Value)
End Sub

Figure 3.21 shows an application with   a HScrollBar control linked to a Label control. The Label   control displays the Value of the HScrollBar. When you move   the scroll bar, the label is updated with the new value. In this sample the    Minimum is 0, the Maximum is 100, SmallChange is   10, and LargeChange is 20. The complete code for this sample can be   found in the code list for this book.

 

以下是一个scrollbar的使用Demo

http://www.java2s.com/Tutorial/CSharp/0460__GUI-Windows-Forms/UseScrollBartocontrolPicture.htm

 

23.24.1.Use ScrollBar to control Picture
Use ScrollBar to control Picture
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());
  }
}

 

 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值