469,643 Members | 1,781 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,643 developers. It's quick & easy.

read-only textbox

I would like to:
1] Output messages to a user in a scrollable control
2] Allow the user to copy selected text from this control
3] The user should be prevented from modifying the text in any way
4] I would like my program to have control over the background and
foreground colors of this control

I was examining the textbox WinForms control and found the read-only
property. Setting this property satisfies requirements 1 - 3, but I am
having trouble with requirement 4. Specifically, I am setting the
TextBox.ForeColor property, but the control ignores this command.

Do I need to subclass this control in order to make this work? Is
subclassing as simple as overriding the control's ForeColor property?
Nov 15 '05 #1
2 19222

"Brian P. Bailey" <NS************@hotmail.com> wrote in message
news:30vCb.378684$ao4.1263140@attbi_s51...
I would like to:
1] Output messages to a user in a scrollable control
2] Allow the user to copy selected text from this control
3] The user should be prevented from modifying the text in any way
4] I would like my program to have control over the background and
foreground colors of this control

I was examining the textbox WinForms control and found the read-only
property. Setting this property satisfies requirements 1 - 3, but I am
having trouble with requirement 4. Specifically, I am setting the
TextBox.ForeColor property, but the control ignores this command.

Do I need to subclass this control in order to make this work? Is
subclassing as simple as overriding the control's ForeColor property?


Not sure how you are doing it but this works fine for me:

textBox1.BackColor = System.Drawing.SystemColors.Info;

textBox1.ForeColor = System.Drawing.Color.IndianRed;

textBox1.ReadOnly = true;
--
Rocky Moore
www.HintsAndTips.com

Nov 15 '05 #2
I've just figured it out. I must explicitly set the BackColor property at
some point before the control acknowledges my setting of the ForeColor
property. For example, the following results in the system ignoring my
textBox1.ForeColor call:
// In the constructor...
textBox1.ReadOnly = true;

// In an event handler...
textBox1.ForeColor = System.Drawing.Color.Blue;
But if I add the following statement to either the constructor or the event
handler, the ForeColor will change as expected:

textBox1.BackColor = System.Drawing.SystemColors.Window;

So, it seems that I must explicitly change the BackColor in order to nudge
the control out of its default-read-only-colors state. This doesn't matter
to me in my current application, but it seems redundant. I would think the
control should be nudged if I explicitly set the ForeColor as well.
Not sure how you are doing it but this works fine for me:

textBox1.BackColor = System.Drawing.SystemColors.Info;

textBox1.ForeColor = System.Drawing.Color.IndianRed;

textBox1.ReadOnly = true;
--
Rocky Moore
www.HintsAndTips.com

Nov 15 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Gunnar | last post: by
6 posts views Thread by Steve | last post: by
12 posts views Thread by Steven T. Hatton | last post: by
2 posts views Thread by Sandman | last post: by
4 posts views Thread by Ollie Cook | last post: by
1 post views Thread by Jose Reckoner | last post: by
6 posts views Thread by arnuld | last post: by
4 posts views Thread by zl2k | last post: by
5 posts views Thread by Thomas Christensen | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.