How to make a RichTextBox content not to be able to select?
Hi!
I want to make a RichTextBox content not to be able to be selected.
The problem is that i can't use enable=false, because the RichTextBox is multiline and has scrollbars and if i disable it, then the scrollbars can't be scrolled.
Thanks for yor answer!
Re: How to make a RichTextBox content not to be able to select?
Do you mean selected or do you mean read only ? There's a 'ReadOnly' property on the rich text box which prevents users from changing the contents.
Darwen.
Re: How to make a RichTextBox content not to be able to select?
Quote:
Originally Posted by darwen
Do you mean selected or do you mean read only ? There's a 'ReadOnly' property on the rich text box which prevents users from changing the contents.
Darwen.
I know about the ReadOnly property, but this doesn't solve the problem. Even with ReadOnly=true the conetent of a rich texbox can be selected.
So, i mean selected.
Re: How to make a RichTextBox content not to be able to select?
there is no property as yet. you can manually capture mouse down event and key pressed event to determine whether user is trying to select the text.
Re: How to make a RichTextBox content not to be able to select?
Quote:
Originally Posted by Andy Tacker
there is no property as yet. you can manually capture mouse down event and key pressed event to determine whether user is trying to select the text.
Yes, this is the solution!
When the user tryes to click in the RichTextBox then i make focus an another component.
Re: How to make a RichTextBox content not to be able to select?
you can roll your own richtextbox which inherits from richtextbox, and disable the control from ever being able to gain focus:
Code:
public class ViewOnlyRichTextBox : System.Windows.Forms.RichTextBox {
// constants for the message sending
const int WM_SETFOCUS = 0x0007;
const int WM_KILLFOCUS = 0x0008;
protected override void WndProc(ref Message m) {
if(m.Msg == WM_SETFOCUS) m.Msg = WM_KILLFOCUS;
base.WndProc (ref m);
}
}