Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Richtextbox changes SelectionColor automatically

$
0
0
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.

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>