vb.net - 如何在 RichTextBox 中隐藏插入符号?

标签 vb.net .net-3.5

就像标题一样:我在网上搜索了答案,但我找不到在 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/

相关文章:

c# - 数据表Select语句问题

json - 当我想存储 UTC 日期时间时,如何停止 Entity Framework 转换 Json UTC 日期时间

c# - 使用 ASP.NET 表单例份验证,如何让图像显示在登录屏幕上?

.net-3.5 - 在哪里可以找到 .Net 类 3.5 -> 4.0 的更改和错误修复列表?

c# - 文件.复制后文件.删除

vb.net - 不区分大小写

vb.net - 作为 TS RemoteApp 的 ClickOnce 仅在线应用程序

C# 同时重写和新建

c# - 将应用程序从 dotnet 2.0 迁移到 3.5

C# WPF 按钮点击