调整文本框上的自动完成下拉列表宽度

发布于 2024-07-06 09:13:00 字数 150 浏览 7 评论 0原文

我正在使用自定义 AutoCompleteSource 设置的 .NET 2 winforms 应用程序中的文本框。 无论如何,我可以通过代码增加包含自动完成建议的列表的宽度吗?

理想情况下,我希望在不增加文本框宽度的情况下执行此操作,因为用户界面中的空间不足。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

丶视觉 2024-07-13 09:13:00

据我所知,您可以自动调整文本框的大小,使其仅在需要时才变宽,而不是始终与最长的文本一样宽。

示例来自 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

结束类

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

一花一树开 2024-07-13 09:13:00

嗯,确实没有直接的方法。 您可能必须求助于 TextBox 的子类化(在 Windows API 意义上)才能做到这一点,即使如此,仍然需要进行大量猜测。

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.

抱猫软卧 2024-07-13 09:13:00

据我所知,TextBox 类包装了 Windows 附带的完整 AutoComplete API。 遗憾的是,这一事实无法“移植”到 .NET 框架的其他部分。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文