views:

36

answers:

1

I have an application where in the end user can change the color of the form, textboxes, labels, buttons during run time. Let us say that if a form is opened and the user has changed the form color from blue to green. To affect the color settings the existing form has to be closed and re-opened as I'm setting the form color in the Form_Load event. I saw many applications where-in the changes of color would apply to all open forms, buttons, labels etc.

Kindly suggest me appropriate methods to achieve dynamic form coloring. Your help is greatly appreciated.

+2  A: 

You change the form's BackColor. Any need to reopen the form.

Change the Backcolor of the form, and recursively the childs, à la:

// forms background color
this.BackColor = yourNewColor

// controls background color
foreach c Control in this.Controls
 c.BackColor = yourColor
serhio
Use recursion in your case, because controls can contain other controls.. :)
igor
@igor: I leave OP doing it by itself, as training.
serhio