How to add scrollbars to c # form

For some reason, adding a vertical scrollbar works with my code.

I can not add both the vertical scrollbar and horizontal .

private void textBox1_TextChanged(object sender, EventArgs e) { textBox1.ScrollBars = ScrollBars.Vertical; } 
+4
source share
4 answers

You should set both ScrollBars and WordWrap as follows:

 textBox1.ScrollBars = ScrollBars.Both; textBox1.WordWrap = false; 

NOTE All the above settings are performed 1 time. No need to put code in a TextChanged event TextChanged .

+7
source
 private void textBox1_TextChanged(object sender, EventArgs e) { textBox1.ScrollBars = ScrollBars.Both; } 

ScrollBars. [Value] is enum : Valid values ​​are Horizontal, Vertical, None, and Both.

+2
source

If you want to add a Vertical ScrollBar to your form. Then copy and paste this code into the LOAD EVENT form. as

 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); } 
0
source

you do not need to write code for this. Just change the textBox properties. For both scrollbars, if Multiline is set to True, set ScrollBars to Both and set WordWrap to False in the properties. There is no need to write code at all, as it is for WinForms.

0
source

All Articles