Windows Develop Bookmark and Share   
 index > Windows Forms Designer > Readonly textbox - change forecolor
 

Readonly textbox - change forecolor

I have a VB7 app that needs the text color of a readonly textbox to be set in code : red if out of spec, black if in spec. I can't do it!!!
MigrationUser 1  Thursday, December 04, 2003 5:43 PM
Hi ,
I too need a solution for this issue. I am doing IM Application. In that i am using readonly textbox for showing chat message. In that, for "I said: " or " chatuser said: " I would like to show a different color and for msg i need to show black color.

Any one pls help me how to do this.

Regards,
M.Sathya.
msathya03  Monday, April 13, 2009 1:47 PM

@MSathya: I would recommend using a RichTextbox control if you need to change the color of certain parts of the text... especially if it is certain words or patterns. The following code may illustrate this...

        Dim WordToColor As String = "I said: "
        Dim idx As Int32 = 0
        Do While idx <> -1
            idx = RichTextBox1.Text.IndexOf(WordToColor, idx)
            If idx <> -1 Then
                With RichTextBox1
                    .SelectionStart = idx
                    .SelectionLength = WordToColor.Length
                    .SelectionColor = Color.Red
                End With
                idx += WordToColor.Length
            End If
        Loop


Dig-Boy  Thursday, April 16, 2009 12:31 AM
Hi Dig-Boy,
I am developing for Windows mobile 6.0. It doesn't have RichTextBox option. :(
msathya03  Friday, April 17, 2009 9:59 AM
I haveaVB7appthatneedsthetextcolorofareadonlytextboxtobesetincode:redifoutofspec,blackifinspec.Ican'tdoit!!!

The work around is to use the TextBox without setting the read-only flag and then capture the TextChanged event. the code below works fine.

public partial class Form1 : Form
    {
        string TextBoxText = "";
        public Form1()
        {
            InitializeComponent();
            textBox1.TextChanged += new EventHandler(textBox1_TextChanged);
            TextBoxText = textBox1.Text;
            textBox1.ForeColor = Color.Red;
            textBox1.BackColor = SystemColors.Control;

        }

        void textBox1_TextChanged(object sender, EventArgs e)
        {
             textBox1.Text= TextBoxText;


        }
    }

Kavitesh Singh.
Kavitesh Singh  Monday, July 13, 2009 1:21 PM

You can use google to search for other answers

Custom Search

More Threads

• fake custom property - designer notification
• update other form
• Looking for free "gauge" control
• Mdi form
• Override mappingname property show custom list
• ControlPaint.DrawBorder3D Overrides Form Backcolor
• Add design time support to wrapped user controls
• Disabling property editing at design time
• ShowUI method crashes when coupled with Form.Close
• MonthCalendar cannot be modified in the designer