Non so se anche a voi è capitato ma mi sembra utile postarlo. Se hai un TextBox con una scrollbar e vuoi nascondere la scrollbar quando questa è inutile, come si può fare?
Ecco il codice (txtTesto è il nostro TextBox):
1: Private Sub txtTesto_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtTesto.TextChanged
2: Static busy As Boolean
3: If busy Then Exit Sub
4: busy = True
5:
6: With sender
7: Dim tS = TextRenderer.MeasureText(.Text, .Font)
8: Dim Hsb = .ClientSize.Height < tS.Height + .Font.Size
9: Dim Vsb = .ClientSize.Width < tS.Width
10:
11: If Hsb And Vsb Then
12: .ScrollBars = ScrollBars.Both
13: ElseIf Not Hsb And Not Vsb Then
14: .ScrollBars = ScrollBars.None
15: ElseIf Hsb And Not Vsb Then
16: .ScrollBars = ScrollBars.Vertical
17: Else
18: .ScrollBars = ScrollBars.Horizontal
19: End If
20: End With
21: busy = False
22: End Sub
Ciao!