473,406 Members | 2,620 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 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 19705

"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, sizeof(int)) { // do something with number } My...
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 returns itself. How can I find out the number of...
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. What's wrong with them. This is the code I...
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 or her with new material I am currently doing...
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 appreciate some guidance. I am trying to 'time out' a...
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 viewer. Thanks!
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 Visual Studio C# Express. I have successfully made...
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 to store each line from a file into a *...
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: number of Data, Data array Suppose I have...
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 subprocess sometimes hang, in which case a call to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.