如何在c#表单中添加滚动条
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19011948/
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 to add scrollbars in c# form
提问by user2788405
For some reason only adding a vertical scroll bar works with my code.
出于某种原因,仅添加垂直滚动条适用于我的代码。
I can't seem to add BOTH a vertical and horizontalscroll bar.
我似乎无法同时添加垂直和水平滚动条。
private void textBox1_TextChanged(object sender, EventArgs e)
{
textBox1.ScrollBars = ScrollBars.Vertical;
}
回答by MikeTheLiar
回答by King King
You have to set both ScrollBars
and WordWrap
like this:
您必须同时设置ScrollBars
并WordWrap
像这样:
textBox1.ScrollBars = ScrollBars.Both;
textBox1.WordWrap = false;
NOTE: All the settings above are done 1 time. No need to place the code in the TextChanged
event handler.
注意:以上所有设置都完成了 1 次。无需将代码放在TextChanged
事件处理程序中。
回答by Pir Fahim Shah
If you want to add Vertical ScrollBar in your Form. Then copy and paste this code in FormLOAD EVENT. like
如果要在表单中添加垂直滚动条。然后将此代码复制并粘贴到Form LOAD EVENT 中。喜欢
private void Form1_Load(object sender, EventArgs e)
{
VScrollBar vScroller = new VScrollBar();
vScroller.Dock = DockStyle.Right;
vScroller.Width = 30;
vScroller.Height = 200;
vScroller.Name = "VScrollBar1";
this.Controls.Add(vScroller);
}
回答by Mlarnt90
you don't need to write a code for this. Just change the properties of textBox. For both scroll bars, if Multiline set to True, then set ScrollBars to Both and set WordWrap to False in properties. No need for writing code at all since this is for WinForms.
您无需为此编写代码。只需更改 textBox 的属性即可。对于两个滚动条,如果 Multiline 设置为 True,则在属性中将 ScrollBars 设置为 Both 并将 WordWrap 设置为 False。根本不需要编写代码,因为这是针对 WinForms 的。
回答by Bob
Drag and drop vertical or horizontal scroll bars from ToolBox onto the form. Dock to right and bottom.
将垂直或水平滚动条从 ToolBox 拖放到窗体上。停靠在右侧和底部。
Alternatively code location and size in Form_Load and Form_Resize. Another way is to use GDI32
. If GDI32
is used you don't need to add scroll bars from the ToolBox
or programmatically. Call SetScrollRange
and SetScrollPos
in Form_Load and Form_Resize. Scrollbar attached to form will appear automatically. Suggest using SetScrollInfo in GDI32 to create proportional scrollbar. If you do not call SetScrollInfo a non-proportional scrollbar will be created. This is a scrollbar where the thumb size stays constant as window resizes.
或者在 Form_Load 和 Form_Resize 中代码位置和大小。另一种方法是使用GDI32
. 如果GDI32
使用,则不需要从ToolBox
或 以编程方式添加滚动条。在 Form_Load 和 Form_Resize 中调用SetScrollRange
和SetScrollPos
。附加到表单的滚动条将自动出现。建议使用 GDI32 中的 SetScrollInfo 来创建比例滚动条。如果你不调用 SetScrollInfo 一个非比例滚动条将被创建。这是一个滚动条,当窗口调整大小时,其中的拇指大小保持不变。