forked from dotnet/project-system
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFixedWidthTextBox.vb
31 lines (24 loc) · 1 KB
/
FixedWidthTextBox.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
' Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. See the LICENSE.md file in the project root for more information.
Imports System.Windows.Forms
Namespace Microsoft.VisualStudio.Editors.PropertyPages
''' <summary>
''' This is a class to automatically set the height of textbox.
''' </summary>
Friend Class FixedWidthTextBox
Inherits TextBox
Protected Overrides Sub OnTextChanged(e As EventArgs)
CalculateAndSetHeight()
MyBase.OnTextChanged(e)
End Sub
Protected Overrides Sub OnSizeChanged(e As EventArgs)
CalculateAndSetHeight()
MyBase.OnSizeChanged(e)
End Sub
Private Sub CalculateAndSetHeight()
Using graphics = CreateGraphics()
Dim area = graphics.MeasureString(Text, Font, Width)
Height = CInt(area.Height)
End Using
End Sub
End Class
End Namespace