TextBox-显示整个文本 [英] TextBox- Display Whole Text

查看:122
本文介绍了TextBox-显示整个文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以编程方式创建了一些文本框,我想在其中添加一些文本。但他们没有显示整个文字,我必须点击并向左拖动才能显示所有文字..



不是有选项,也许AutoSize,AutoFit或类似的东西?



谢谢!

I create programatically some textboxes, and I want to put some text in them. But they don''t display the whole text, I have to click and drag to left to show all text..

Isn''t there an option, maybe "AutoSize", "AutoFit" or something like that?

Thank you!

推荐答案

否 - 没有标准的方法来改变文本框的大小,或者字体大小以使文本适合显示。

但是,如果你使它成为多行并启用ScrollBars它可以做一些事情喜欢你想要的东西。



如果你必须有一个重新调整大小的控件,那么我怀疑你必须自己编写它。
No - there is no standard way to change either the size of the text box, or the font size to fit the text into the display.
However, if you make it multi line and enable ScrollBars it can do something like what you want.

If you must have a re-sizing control, then I suspect you will have to write it yourself.


您可以使用 TextRenderer http://msdn.microsoft.com/en-us/library/system.windows.forms.textrenderer.aspx [ ^ ]到确定文本框在文本框的 TextChanged 事件中需要的大小 - 或者更好地按照OriginalGriff的建议进行,并使自己的重新调整自定义控件继承自 System.Windows.Forms.TextBox

示例

You can use TextRenderer http://msdn.microsoft.com/en-us/library/system.windows.forms.textrenderer.aspx[^] to determine what size the text box needs to be in the TextChanged event of the textbox - or better yet do as OriginalGriff suggests and make your own re-sizing custom control inheriting from System.Windows.Forms.TextBox
Example
private void textBox1_TextChanged(object sender, EventArgs e)
{
    TextBox t = (TextBox)sender;
    Size s = TextRenderer.MeasureText(t.Text, t.Font);
    t.Width = s.Width;
}


更改文本模式(单行 - >多行)
in text box properties change the text mode(single line->multiline)


这篇关于TextBox-显示整个文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆