views:

1731

answers:

3

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.

A: 

Hmmm, there's no direct way really. You'd probably have to resort to subclassing (in the Windows API sense) the TextBox to do that, and even then there'd be a lot of guessing to do.

dguaraglia
+1  A: 

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

Nikki9696
A: 

As far as I know the TextBox class wraps the complete AutoComplete API that comes with Windows. Alas, this fact is not "portable" to other parts of the .NET framework.

Michael Damatov