Thanish K
Thanish K

Reputation: 37

Changing button's background color from another winform

I have this project that has quite a number of winforms and how do I change button background color or text color or any other attributes from another winform? I'm currently using delegate and this is not efficient as I will need to create a new delegate everytime I want to change a new attributes. Is there any better way to do it?

Upvotes: 0

Views: 96

Answers (1)

Caius Jard
Caius Jard

Reputation: 74595

In the Designer, click on your button

Ensure that GenerateMember is true and Modifiers is public. Name the button using PascalCase, for example CancelButton

Now you can in some other form:

var formWithButton = new FormX();
formWithButton.CancelButton.BackColor = Color.Black;

If you have a large number of changes to make, perhaps consider a theming framework instead

Upvotes: 1

Related Questions