Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use own RGB value to change Winform Button ForeColor?

How can I change the Buttons's ForeColor with my own RGB value (example: 131;160;21) programmatically (not from designer)? The property R, G and B in Button-control are only "get" property and not "set".

I want to change it when the "Enabled" property is changed and I have also implemented event handler for EnabledChanged event.

Thank you in advance.

like image 834
MagB Avatar asked Jul 28 '11 10:07

MagB


People also ask

How do I change the color of a button in Windows Forms?

Step 2: Drag the Button control from the ToolBox and drop it on the windows form. You are allowed to place a Button control anywhere on the windows form according to your need. Step 3: After drag and drop you will go to the properties of the Button control to set the BackColor property of the Button.

Which property is used to set the background color to the button control *?

The BackColor property is an ambient property. An ambient property is a control property that, if not set, is retrieved from the parent control. For example, a Button will have the same BackColor as its parent Form by default.

Which property of the control enables you to change the back color of the text of the control?

The CSS background-color property allows you to change the background color of an HTML element.

Which of the following property in USD to change the background color of a component control in C# Windows Form applications?

Using BackColor property you can set the background color of the button. Using BackgroundImage property you can set the background image on the button.


1 Answers

Use Color.FromArgb Method

MyButton.ForeColor = Color.FromArgb(255,255,255);

If you need to control the alpha too, use the overloaded method.

like image 168
Ranhiru Jude Cooray Avatar answered Nov 21 '22 01:11

Ranhiru Jude Cooray