1

I am working on WPF, I want to change Background---color of textbox ( txtStatus.Background= white), but it is giving ERROR. Here my code is:

public Window2()
            {
                InitializeComponent();
                txtStatus.Text = "Current Operation: NULL";
                txtStatus.Background= white
            }
5
  • 3
    BTW, you should NOT be manipulating UI elements in procedural code, that's what XAML is for, y'know... Commented Jul 1, 2013 at 15:42
  • @HighCore It's just fine to do in some cases. (this is also why WPF has converter classes) Commented Jul 1, 2013 at 16:18
  • If you're databinding, can you tell what your control is going to look like given a specific state until you see it during runtime? no, you can't, which makes it no different from this. These bindings can also be created from backend code, and do not need to be defined in XAML per sé. I'll agree that winforms is a dinosaur, especially when compared to XAML but it's not useless, and everything but random. It's also imaginable that you want to build a control procedurally, not using xaml, in which case this is a valid question indeed. Commented Jul 1, 2013 at 16:24
  • There's no need to get that defensive about it, your remark stands fine. I just noted that it's not always the case. Commented Jul 1, 2013 at 16:25
  • 1
    there are some times where producing UI in procedural code is perfectly acceptable. for most cases it isn't the best idea, but it isn't inherently wrong. Commented Jul 1, 2013 at 19:55

1 Answer 1

7

You need to use Brushes:

txtStatus.Foreground = Brushes.White;

It contains a lot of colors, though if you want to use aRGB values then you can do it like this:

txtStatus.Foreground = new SolidBrush(Color.FromArgb(255, 0, 0, 255));
Sign up to request clarification or add additional context in comments.

1 Comment

No problem Dua Ali. You haven't marked it as an aswer, yet. To do it you have to click check mark under vote count :) Take a look at FAQ

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.