1 Replies - 1057 Views - Last Post: 30 December 2012 - 03:07 PM Rate Topic: -----

#1 charqus  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 07-February 10

richTextBox selectedText WinForms

Posted 30 December 2012 - 02:09 PM

Hello guys. I have a simple Windows Form Application, and I docked on my form an richTextBox. I have set the next lines:
        public Form1()
        {
            InitializeComponent();
            this.Load += new EventHandler(Form1_Load);
        }

        void Form1_Load(object sender, EventArgs e)
        {
            richTextBox1.Text = "This\nis\nmy\nlittle\ntest!";
            richTextBox1.ReadOnly = true;
            richTextBox1.ZoomFactor = 3.0f;
            richTextBox1.SelectAll();
            richTextBox1.SelectionAlignment = HorizontalAlignment.Center;
        }

And when I debug the program, with my mouse I can select the text from my richTextBox, and that cursor for typing appears on my richTextBox ( please check the screenshots ):
cursor: http://img132.images...06/75852424.png
cursor: http://img28.imagesh...09/43502289.png
selected text with mouse: http://img715.images...18/28203295.png

Actually, I tried with richTextBox.Enabled = false, but this property change my background color and my foreground color of my richTextBox...

Is This A Good Question/Topic? 0
  • +

Replies To: richTextBox selectedText WinForms

#2 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3834
  • View blog
  • Posts: 13,583
  • Joined: 12-December 12

Re: richTextBox selectedText WinForms

Posted 30 December 2012 - 03:07 PM

The ReadOnly property simply means that the user cannot type in the textbox. It doesn't prevent the default Windows behaviour of allowing someone to drag across text to select it.

The Enabled property would completely disable it, but you've said that this is not suitable.

I would just change the cursor and accept the default Windows behaviour.

If you wanted to replicate the Enabled behaviour, but without the change in colours, then you might work with code for a number of mouse/selection events, or position another control in front of the rich-text box. I would recommend just changing the cursor.

Properties -> Cursor -> No.

This post has been edited by andrewsw: 30 December 2012 - 03:10 PM

Was This Post Helpful? 2
  • +
  • -

Page 1 of 1