有一个可选的(这意味着我可以复制从标签文本),在本地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.