[RESOLVED] Changing Control colors
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9

Thread: [RESOLVED] Changing Control colors

  1. #1
    Join Date
    Mar 2011
    Posts
    59

    [RESOLVED] Changing Control colors

    I know this is silly, but I am unable to change the colors of my controls by either the properties panel or with code. Anyone ever have this problem? Im using the latest version of Visual studio. the Code i am using is


    if (value1 > value2)
    {
    this.temp.ForeColor = Color.Yellow;
    }

    Basically I would like my text color to change to yellow while the value2 is lower than value1 when they are equal green and over red.

    I know I dont have the Green or the red written in, although I can not even get yellow to display, it comes out black (no change). If anyone can help that would be great! Thanks in advance!

  2. #2
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,090

    Re: Changing Control colors

    I don't think the problem lies with setting the colours, I think the problem is with your condition, ie. : value1 > value2

    I'd suggest setting a break point on your if condition, then step through your code, line by line - that way, you could easily identify if value2 is indeed smaller than value1.

    I sinc erely hope this helps you!

  3. #3
    Join Date
    Mar 2011
    Posts
    59

    Re: Changing Control colors

    Yeah I guess I should have said that I already did that before. Ive even set a break point inside the IF to make sure that it steps inside and runs the line of code, and it does every time its supposed to but alas no color change.

  4. #4
    Join Date
    Mar 2011
    Posts
    59

    Re: Changing Control colors

    Are there any settings that I would have to change in order to be able to change the color of text in a text box? Im really at a loss as to why my text is ONLY black. Even if I change the foreground to a different color it stays black.

  5. #5
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,090

    Re: Changing Control colors

    Interesting.... Could you perhaps post your full code / project here? Then we can possibly identify why it does this.

  6. #6
    Join Date
    Jan 2010
    Posts
    1,099

    Re: Changing Control colors

    Yes, we need to see more. The name of the member field (temp) looks awfully suspicious - maybe you've mixed up a control or two...
    So - post at least the containing method, and tell us what temp is, why it's called "temp" (what's temporary about it) and where it's value is coming from.

  7. #7
    Join Date
    Mar 2011
    Posts
    59

    Re: Changing Control colors

    Sadly my project is far to large for me to post the entire code, although I did discover my issue. It would seem in I am not allowed to change the color on "Read only" set text box. When I make read Only = false, the color of my text changes.

    My next question is, Is there any way for me to not allow the user to click into the text box? Or would I be better off using a Label? I only want information display on this particular control, so if a label is a better Idea maybe Ill do that. Thanks!

  8. #8
    Join Date
    Jan 2010
    Posts
    1,099

    Re: Changing Control colors

    If by "not allow the user to click into" means that the control shouldn't be editable - then you should use a label. (You can still detect a click, and do something if you want, but the user can't edit the text the way a text box makes it possible).

  9. #9
    Join Date
    Mar 2011
    Posts
    59

    Re: Changing Control colors

    Yes it looks like Labels is the way to go for me. Sorry for all the silly questions I ask, Ive really only been working in the software engineering field for about 4 months now. Oh and temp is for temperature not temporary. Checking the values of temperatures on some machines VS the set temperature on the hardware controls. If the Machine is below the set temp the text is to be yellow, if its on the temp green, if its above the temp red. Simple enough just didnt know I couldnt change the colors of a read only text box. Now I know, knowing is half the battle yada yada yada all american hero or something.
    Last edited by DKS1282; May 13th, 2011 at 09:00 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center