.NET Framework:如何使RichTextBox真正只读?
将 RichTextBox 设置为“ReadOnly”并不会阻止通过双击嵌入对象(如方程)来编辑它们。 我可以禁用该控件,但会出现灰色背景(不能仅使用 BackColor 进行更改)并且无法滚动。 我尝试在派生类中重写 OnDoubleClick 但没有成功。
Setting RichTextBox as “ReadOnly” doesn't prevent embedded objects (like equations) from being edited by double-clicking them. I could disable the control but then there is a gray background (can't be just changed with BackColor) and no way to scroll. I tried to override OnDoubleClick in a derived class but no success.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我找到了解决办法! :) 在派生类中:
I found a solution! :) In a derived class:
我遇到了类似的问题,Entrase 的答案是一个好的开始。 不幸的是,该控件仍然允许选择文本并删除它。 我最终使用了以下代码:
I had a similar problem and the answer from Entrase was a good start. Unfortunately, the control still allowed selecting text and deleting it. I ended up using the following code:
嗯...只需尝试在双击时将 Sellength 设置为 0。 没有只读/锁定属性吗?
Hmm... Just try setting Sellength to 0 on doubleclick. Isn't there a readonly/locked property?
可以按如下方式完成
1) 将 RichTextBox 属性 ReadOnly 设置为 true
2) 转到 Properties->Appearance->BackColor 并将颜色设置为 Window
This can be done as follows
1)Set the RichTextBox property ReadOnly to true
2)Go to Properties->Appearance->BackColor and set color as Window