Click here to Skip to main content
15,885,914 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using c# 2010 for windows forms development.
I have a form having multiple containers in it and filled with many buttons.
I want to change FlatAppearance.FlatStyle property of all buttons while loading the form.
please also note that the value of the property FlatStyle to be taken from a database.

Hope someone can help me.
Thanks in advance.
Jim
Posted
Comments
[no name] 15-Sep-13 6:56am    
"Hope someone can help me", for someone to help you, you would first have to ask a question or describe some sort of a problem.
Changing properties on a button? Thousands of examples if you had searched for them.
Finding the buttons on a form? Thousands of examples if you had searched for them.
Getting data from a database? Millions of examples if you had searched for them.
BillWoodruff 15-Sep-13 11:37am    
You may also find this link useful: http://stackoverflow.com/a/253962/133321

1 solution

Check this: http://stackoverflow.com/questions/3419159/how-to-get-all-child-controls-of-a-windows-forms-form-of-a-specific-type-button#answer-3426721[^]

The sample given is returning textboxes, but of course you can use it to get all buttons instead. Simply iterate and change that property - it is irrelevant whether it's value is coming from a database or not.
 
Share this answer
 
Comments
jim1972 15-Sep-13 7:20am    
thanks for the instant reply. but in that link, its just giving the count using LINQ.
If you can narrate how to assign the FlatStyle property of all buttons using similar
recursive function, would be highly appreciated.
thanks
Zoltán Zörgő 15-Sep-13 7:26am    
Something like this:

foreach(var btn in GetAll(this,typeof(Button)))
{
(btn as Button).FlatStyle = FlatStyle.Flat;
}
jim1972 15-Sep-13 7:30am    
Ohh, it worked....
thanks alot Zoltan...
I just added the below...

foreach(Button b in c)
{
b.Text = "Sample Caption";
b.FlatStyle = FlatStyle.Flat;
}
BillWoodruff 15-Sep-13 11:29am    
If Zoltan's answer "worked for you," then, please, accept it as the answer, and upvote it: he's worked hard for you, and deserves it :)
BillWoodruff 15-Sep-13 11:37am    
Nice work, Zoltan ! Upvoted.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900