Good Morning All,

Let me start by saying I am completely new to programming in c#, however I do have some VBA experience. That being said I have hopefully a simple thing I am stuck on.

On a windows form I have a textbox that I have set READONLY = TRUE.
I have created a "EDIT" button, once clicked it makes the box writeable and puts cursor to front.

        txtBodyOpen.ReadOnly = false;
        txtBodyOpen.SelectionStart = 0;
        txtBodyOpen.SelectionLength = 0;

The issue is the box always stays greyed out when I want the user to edit the box. I was looking to change the background color of the box back to WHITE, to show the user that its EDITABLE when I click button.

Can't seem to find anything that works to change text background color back to white?

much appreciated!

Recommended Answers

All 7 Replies

Try to use the property enabled instead of the ReadOnly to see what happens, i dont play too much with windows forms but in that would work.

use Enable property (not ReadOnly):

public partial class Form1 : Form
        public Form1()
            textBox1.Enabled = false;
            textBox1.Text = "Some text";

        private void button1_Click(object sender, EventArgs e)
            textBox1.Enabled = true;
            textBox1.SelectionStart = 0;
            textBox1.SelectionLength = 0;

what does property enabled mean? do?

Enabled property means that the control is accessabled (if set to true). If set to false its not in use (its like readonly).
try it.

it works!!

thanks so much

Glad to hear.
btw... if you are (partly) satisfied with the answer or you get any good idea from the post, you can up vote the post, or mark the thread as answered (so we close it up). Any anyone else who faces these kind of issues gets the solution earlier.
Thx in advance.


Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.