vb.net 如何将 VScrollBar 添加到文本框?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30580712/
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
How do I add a VScrollBar to a textbox?
提问by AfterShotzZHD
I am using a theme from the web for my vb.netapplication and the textboxdoes not have scrollbars or a scrollbar property. The theme did come with a VScrollBar Control, but I don't know how to add code to it to make it scroll the textbox like normal. Can anyone help me?
我正在为我的vb.net应用程序使用来自网络的主题,textbox并且没有滚动条或滚动条属性。主题确实带有VScrollBar Control,但我不知道如何向其添加代码以使其像平常一样滚动文本框。谁能帮我?
These are Custom Controls.
这些是Custom Controls。
It's a Windows Form. (WinForms)
It's a Windows Form. (WinForms)
Textbox and its Properties:
文本框及其属性:


回答by AStopher
Vertical scroll bars can be added to TextBoxform objects, but however they mustbe Multiline:
垂直滚动条可以添加到TextBox表单对象中,但它们必须是Multiline:


This can either be done by setting Multilineto Trueand ScrollBarsto Vertical:
这可以通过设置MultilinetoTrue和ScrollBarsto来完成Vertical:


or it can be done via code, programmatically, as per se:
或者它可以通过代码以编程方式完成,本身:
TextBox1.Multiline = True
TextBox1.ScrollBars = ScrollBars.Vertical
You can set ScrollBarsto be only horizontal, vertical, both, or none (default):
您可以设置ScrollBars为仅水平、垂直、两者或无(默认):


Remember, you should:
请记住,您应该:
- Be sanitizing the user's input if you're sending the textbox's contents off to a database
- Limit the amount of characters that the user can input (see below)
- Be using proper programming techniqueby naming your objects properly, for example, try not to name your textbox
TextBox1
As mentioned above, you may want to show the amount of characters the user can input, for example:
如上所述,您可能希望显示用户可以输入的字符数,例如:


the code for this:
代码:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
text1.MaxLength = 140
charsLeft.Text = "0/" + CStr(text1.MaxLength)
End Sub
Private Sub textHasChanged() Handles text1.TextChanged
charsLeft.Text = CStr(text1.TextLength) + "/" + CStr(text1.MaxLength)
End Sub

