vb.net 如何使用滚动条更改文本框的值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17266259/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 14:00:57  来源:igfitidea点击:

How to use a scrollbar to change the value of a text box

vb.net

提问by Jose M.

I have a scrollbar and I would like the scroll bar to change the value of txtRangeSpread textbox by 10 if I scroll to the right and by -10 if I scroll to the left.

我有一个滚动条,如果我向右滚动,我希望滚动条将 txtRangeSpread 文本框的值更改 10,如果我向左滚动,则更改 -10。

Can I do this?

我可以这样做吗?

采纳答案by matzone

Assumed it HScrollbar1

假设它 HScrollbar1

HSCrollBar1.Maximum = 19
HSCrollBar1.Minimum = -10
HSCrollBar1.SmallChange = 1

And changedvalue event

和changedvalue事件

Private Sub HScrollBar1_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles HScrollBar1.ValueChanged
    txtRangeSpread.Text = Format(HScrollBar1.Value)
End Sub 

To link both textbox and scrollbar .. maybe you can do that in form load event or activate event or maybe button click event ..

链接文本框和滚动条..也许你可以在表单加载事件或激活事件或按钮点击事件中做到这一点..

txtRangeSpread.Text = "0"
HScollBar1.Value = val(txtRangeSpread.Text)

回答by MindingData

See here : http://msdn.microsoft.com/en-us/library/system.windows.forms.scrollbar.scroll.aspxAnd here : http://msdn.microsoft.com/en-us/library/system.windows.forms.scrolleventargs.aspx

请参阅此处:http: //msdn.microsoft.com/en-us/library/system.windows.forms.scrollbar.scroll.aspx此处:http: //msdn.microsoft.com/en-us/library/system .windows.forms.scrolleventargs.aspx

  1. Create an event handler for the scroll event of your scroll bar.
  2. The eventargs has arguments for NewValue and OldValue. Checking which one is larger will tell you which way the user is scrolling.
  3. Update your textbox accordingly.
  1. 为滚动条的滚动事件创建一个事件处理程序。
  2. eventargs 具有 NewValue 和 OldValue 的参数。检查哪个更大将告诉您用户滚动的方式。
  3. 相应地更新您的文本框。

Although some issues you may face are that event will be fired for any scroll event (e.g. drag or click), so you may get values outside of ranges that you are expecting.

尽管您可能面临的一些问题是任何滚动事件(例如拖动或单击)都会触发事件,因此您可能会获得超出预期范围的值。