I have the following code :

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace PentruTestari
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            richTextBox2.Text = "int int";
            richTextBox2.SelectionStart = 0;
            richTextBox2.SelectionLength = 7;
            richTextBox2.SelectionColor = Color.Red;
            richTextBox2.SelectionLength = 0;
            richTextBox2.SelectionStart = 4;
            richTextBox2.SelectionColor = Color.Black;
        }
        private void richTextBox2_Click(object sender, EventArgs e)
        {
            MessageBox.Show(richTextBox2.SelectionColor.ToString());
        }
    }
}

Every time I click right before the second "int" , the SelectionColor is black. But when I click at the middle of the first "int" and then click back at the beginning of the first "int" the SelectionColor is red and it should remain black.
I have this problem in a project I am working at and this is the reproduction of the problem.

I will give any extra details.

Edited 3 Years Ago by Fame95

Is it due to the overlapping selection lengths? You have 0 to 7 and 0 to 4 which obviously both include 0-4.

Well I firstly select from 0 to 7 (lines 22 and 23 ) , then I deselect (line 25) and then I set the selection start at index 4 (line 26) , so there is one selection, I think.

When I try your code it doesn't duplicate the problem you mention. But when I switch the values in lines 25 & 26 I get one "int" in black and one in red. Whenever I click on any of the first 4 characters(including the space) it reports black and on any of the last 3 it reports red. I couldn't get the change that you reported.

I managed to resolve the problem by selecting the space after the word. Thank you !

This question has already been answered. Start a new discussion instead.