有什么方法可以使 .NET Windows 窗体上的标签可突出显示以允许复制文本。我曾尝试使用看起来像标签的文本框来执行此操作,但这会导致光标闪烁。
最佳答案
我认为这非常接近:
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);
如果您需要它跨越多行:
textBox.Multiline = true;
关于c# - 突出显示标签 Windows 窗体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/702754/