472,353 Members | 2,211 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,353 software developers and data experts.

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 19509

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Gunnar | last post by:
Hello, I've just written a CPP program that reads integers from a binary file, and used this code while (my_ifstram.read( (char* ) &number,...
6
by: Steve | last post by:
Hi, I'm trying to convert a file reading loop into one using streams. The BSD OS read API returns the number of bytes read, but istream::read...
12
by: Steven T. Hatton | last post by:
I know of a least one person who believes std::ifstream::read() and std::ofstream::write() are "mistakes". They seem to do the job I want done. ...
2
by: Sandman | last post by:
Just looking for suggestion on how to do this in my Web application. The goal is to keep track of what a user has and hasn't read and present him...
4
by: Ollie Cook | last post by:
Hi, I am having some difficulty with read(2) and interrupting signals. I expect I am misunderstanding how the two work together, so would...
1
by: Jose Reckoner | last post by:
I'm running python 2.3 on Windows XP. Anyone have a quick small script to convert .DT1 and .DEM data to ASCII or some other format? I don't need a...
0
by: phplasma | last post by:
Hey, I am currently attempting to implement a multi-threaded C# socket, using SSL (.pem file/certification/private key combo) server using...
6
by: arnuld | last post by:
This works fine, I welcome any views/advices/coding-practices :) /* C++ Primer - 4/e * * Exercise 8.9 * STATEMENT: * write a program...
4
by: zl2k | last post by:
hi, there I have a appendable binary file of complex data structure named data.bin created by myself. It is written in the following format: ...
5
by: Thomas Christensen | last post by:
This issue has been raised a couple of times I am sure. But I have yet to find a satisfying answer. I am reading from a subprocess and this...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.