在Windows窗体中选择本机自动调整大小的标签 [英] Native selectable auto-sized label in Windows Forms

查看:181
本文介绍了在Windows窗体中选择本机自动调整大小的标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个可选的(这意味着我可以复制从标签文本),在本地Windows自动可观标签窗体控件?

Is there a selectable (meaning I can copy text from label), auto-sizable label in the native windows forms controls?

需要注意的是透明的文本框为可选择性提供良好服务,而不是为自动调整大小的部分。

Note that transparent a TextBox serves well for selectability, but not for the auto-size part.

推荐答案

您必须衡量自己,并加少许缓冲区,以减少紧张的:

You would have to measure yourself, and add a little buffer to make it less jittery:

textBox1.MinimumSize = new Size(16, textBox1.Height);
textBox1.TextChanged += textBox1_TextChanged;

void textBox1_TextChanged(object sender, EventArgs e) {
  int textWidth = TextRenderer.MeasureText(textBox1.Text, textBox1.Font, Size.Empty,
                                           TextFormatFlags.TextBoxControl).Width;
  textBox1.Width = textWidth + 8;
}

至于唱片公司而言,他们根本绘制文本,所以没有任何可选择的功能,例如,你得到一个TextBox控件。

As far as labels are concerned, they simply draw text, so there isn't any selectable functionality like you get with a TextBox control.

这篇关于在Windows窗体中选择本机自动调整大小的标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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