突出显示标签Windows窗体

cwe*_*ton 8 .net c# windows user-interface winforms

有没有办法让.NET Windows窗体上的标签可以突出显示,以允许复制文本.我试图使用一个看起来像标签的文本框来做到这一点,但这会导致闪烁的光标.

Sam*_*uel 12

我认为这非常接近:

textBox.BackColor = System.Drawing.SystemColors.Control;
textBox.BorderStyle = System.Windows.Forms.BorderStyle.None;
textBox.ReadOnly = true;
textBox.Text = "This is selectable text";
textBox.MouseUp += new MouseEventHandler(
                          delegate(object sender, MouseEventArgs e)
                             { HideCaret((sender as Control).Handle); });

[DllImport("User32.dll")]
static extern Boolean HideCaret(IntPtr hWnd);
Run Code Online (Sandbox Code Playgroud)

如果您需要它跨越多行:

textBox.Multiline = true;
Run Code Online (Sandbox Code Playgroud)


Hen*_*man 6

如果您希望它是一个可预测,良好表现和标准的控件,具有所有键盘和快捷键支持,您只需要一个文本框.然后闪烁的光标是一个正常的有用的功能,为什么要打它?