我一直在做一些环顾四周,但到目前为止,我还没有看到我正在寻找的东西。我有一个TextBox,它被设计成在VB.Net程序中看起来像一个Label,因为Labels不具备TextBox所有相同的东西。我想要在每个轴上显示一个滚动条,当且仅当它实际需要时才会显示。字体对不同的字符使用不同的宽度,这不是我能够为此改变的。
如何将滚动条放在那里?就VB.Net GUI设计而言,我有点绿色,所以涉及30行代码的答案可能会有点难以理解和应用。如果可能的话,我真的需要一些不太复杂的东西。谢谢!
答案 0 :(得分:4)
<强>更新强>
我写了Function
Link
我已经在这里发布了Textbox
。这应该为你做。 (请确保,对于此测试,您的Textbox6
为Textbox1
而不是Private Sub TextBox6_TextChanged(sender As Object, e As EventArgs) Handles TextBox6.TextChanged
If CheckLength(TextBox6.Text) = True Then
TextBox6.ScrollBars = ScrollBars.Vertical
Else
TextBox6.ScrollBars = ScrollBars.None
End If
End Sub
Private Function CheckLength(ByVal longStr As String)
Dim TrueOrFalse As Boolean = False
Dim f As Font = Me.TextBox6.Font
Dim rect As Rectangle = TextBox6.ClientRectangle
Dim charFitted As Integer
Dim linesFitted As Integer
Using g As Graphics = TextBox6.CreateGraphics()
Dim sf As New StringFormat(StringFormatFlags.NoWrap)
sf.LineAlignment = StringAlignment.Center
sf.Alignment = StringAlignment.Near
sf.Trimming = StringTrimming.EllipsisCharacter
sf.FormatFlags = StringFormatFlags.DirectionVertical
g.MeasureString(longStr, f, rect.Size, sf, charFitted, linesFitted)
End Using
If charFitted < longStr.Length Then
TrueOrFalse = True
End If
Return TrueOrFalse
End Function
)
CheckLength
这会检查整个复选框的长度(多行与否),boolean Function
是returns
True
Textbox's Length
{{1}}已超出。
Reguards