Click here to Skip to main content
15,920,704 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all, In my prjcts I have N no of buttons.
How shall I count that buttons through coding?
Posted
Updated 13-Oct-10 17:38pm
v3

1 solution

Count all of the items in the Controls object on your form where the type is Button. Here's the code for C#, it shouldn't be hard at all to convert it to VB.Net (the code uses Linq):

C#
var count = (from ctrl in this.Controls
             where ctrl is Button 
             select ctrl).Count();
 
Share this answer
 
Comments
Dalek Dave 13-Oct-10 15:24pm    
Good Answer.
Hiren solanki 14-Oct-10 1:37am    
nicely spotted.
Simon_Whale 14-Oct-10 7:02am    
good answer never thought of using Linq for looping through the controls collection before

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