CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Nov 2003
    Posts
    39

    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!

  2. #2
    Join Date
    Jan 2002
    Location
    Scaro, UK
    Posts
    5,940

    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.
    www.pinvoker.com - PInvoker - the .NET PInvoke Interface Exporter for C++ Dlls.

  3. #3
    Join Date
    Nov 2003
    Posts
    39

    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.

  4. #4
    Andy Tacker is offline More than "Just Another Member"
    Join Date
    Jun 2001
    Location
    55°50' N 37°39' E
    Posts
    1,503

    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.
    If you think you CAN, you can, If you think you CAN'T, you are probably right.

    Have some nice Idea to share? Write an Article Online or Email to us and You may WIN a Technical Book from CG.

  5. #5
    Join Date
    Nov 2003
    Posts
    39

    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.

  6. #6
    Join Date
    Mar 2004
    Location
    33°11'18.10"N 96°45'20.28"W
    Posts
    1,808

    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);
            }
        }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured