Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adjusting the auto-complete dropdown width on a textbox

I am using a textbox in a .NET 2 winforms app that is setup with a custom AutoCompleteSource. Is there anyway through code that I can increase the width of the list that appears containing the auto complete suggestions?

Ideally I would like to do this without increasing the width of the textbox as I am short for space in the UI.

like image 628
KevB Avatar asked Nov 14 '22 17:11

KevB


1 Answers

Not that I know of, but you can auto-size the Textbox so that it is only wide when it needs to be, rather than always as wide as the longest text.

Example from http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=3311429&SiteID=1

Public Class Form1
Private WithEvents T As TextBox
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    T = New TextBox
    T.SetBounds(20, 20, 100, 30)
    T.Font = New Font("Arial", 12, FontStyle.Regular)
    T.Multiline = True
    T.Text = "Type Here"
    T.SelectAll()
    Controls.Add(T)
End Sub
Private Sub T_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles T.TextChanged
    Dim Width As Integer = TextRenderer.MeasureText(T.Text, T.Font).Width + 10
    Dim Height As Integer = TextRenderer.MeasureText(T.Text, T.Font).Height + 10
    T.Width = Width
    T.Height = Height
End Sub

End Class

like image 181
Nikki9696 Avatar answered Dec 16 '22 08:12

Nikki9696