Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

how to change WinForm controls' text color programatically?


  • Please log in to reply
5 replies to this topic

#1 BobLewiston

BobLewiston

  • Members
  • 69 posts
  • OFFLINE
  •  
  • Local time:05:28 PM

Posted 04 March 2009 - 06:01 PM

Can anybody tell me how to change WinForm controls' text color programatically? I have no problem finding the fields to assign colors to, but the compiler doesn't recognize any color I mention, whether it's something like WindowText, or something like Red.

BTW, I'm using VC# Express 2008.

Edited by BobLewiston, 04 March 2009 - 06:09 PM.


BC AdBot (Login to Remove)

 


#2 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:03:28 PM

Posted 04 March 2009 - 06:19 PM

How are you trying to assign the color to the control? Are you setting it in the properties, or are you trying to do it in the code?

#3 BobLewiston

BobLewiston
  • Topic Starter

  • Members
  • 69 posts
  • OFFLINE
  •  
  • Local time:05:28 PM

Posted 04 March 2009 - 06:49 PM

Programatically - in the code.

#4 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:03:28 PM

Posted 04 March 2009 - 06:54 PM

Why not just use the properties section? If you want to do it by hand, you need to do it in the form constructor, after the form has been initialized.

#5 Billy O'Neal

Billy O'Neal

    Visual C++ STL Maintainer


  • Malware Response Team
  • 12,304 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Redmond, Washington
  • Local time:02:28 PM

Posted 04 March 2009 - 10:38 PM

You need to assign it with a color object. You need to initialize that object. You can't just assign something like "red".

http://msdn.microsoft.com/en-us/library/sy...or_members.aspx

Billy3
Twitter - My statements do not establish the official position of Microsoft Corporation, and are my own personal opinion. (But you already knew that, right?)
Posted Image

#6 BobLewiston

BobLewiston
  • Topic Starter

  • Members
  • 69 posts
  • OFFLINE
  •  
  • Local time:05:28 PM

Posted 04 March 2009 - 10:52 PM

Yeah, I learned you have to say something like
textBox1.ForeColor = System.Drawing.Color.Red;
but here's what I discovered through trial and error: it turns out that when a TextBox's ReadOnly property is set to true (as this one was), the Text property can be modified, but the ForeColor property can't.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users