就像标题一样:我在网上搜索了答案,但我找不到在 VB.NET 中隐藏 RichTextBox 插入符号的方法。
我尝试将 RichTextBox.Enabled 属性设置为 False,然后将背景颜色和前景色更改为非灰色,但这并没有奏效。
提前致谢。
最佳答案
解决方案:
来自:http://www.experts-exchange.com/Programming/Languages/C_Sharp/Q_21896403.html
using System;
using System.Windows.Forms;
using System.ComponentModel;
using System.Runtime.InteropServices;
public class ReadOnlyRichTextBox : System.Windows.Forms.RichTextBox
{
[DllImport("user32.dll")]
private static extern int HideCaret (IntPtr hwnd);
public ReadOnlyRichTextBox()
{
this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.ReadOnlyRichTextBox_Mouse);
this.MouseUp += new System.Windows.Forms.MouseEventHandler(this.ReadOnlyRichTextBox_Mouse);
base.ReadOnly = true;
base.TabStop = false;
HideCaret(this.Handle);
}
protected override void OnGotFocus(EventArgs e)
{
HideCaret(this.Handle);
}
protected override void OnEnter(EventArgs e)
{
HideCaret(this.Handle);
}
[DefaultValue(true)]
public new bool ReadOnly
{
get { return true; }
set { }
}
[DefaultValue(false)]
public new bool TabStop
{
get { return false; }
set { }
}
private void ReadOnlyRichTextBox_Mouse(object sender, System.Windows.Forms.MouseEventArgs e)
{
HideCaret(this.Handle);
}
private void InitializeComponent()
{
//
// ReadOnlyRichTextBox
//
this.Resize += new System.EventHandler(this.ReadOnlyRichTextBox_Resize);
}
private void ReadOnlyRichTextBox_Resize(object sender, System.EventArgs e)
{
HideCaret(this.Handle);
}
}
关于vb.net - 如何在 RichTextBox 中隐藏插入符号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/582312/