473,405 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

How to hide multiple buttons

if i place 20 different buttons on my form, how can i hide them using the for each function or any other function instead of writing the following for each button:
"button1.visible=true"
.
.
.
.
"button20.visible=true"?
Sep 12 '11 #1
1 2215
Frinavale
9,735 Expert Mod 8TB
Add the buttons to a List(Of Button) when you add the buttons to the form. Then you can loop through them.

For example,
Declare a private List(Of Button) member called _buttons. Then, in the code where you're adding the buttons to the form also add them to this list.

Expand|Select|Wrap|Line Numbers
  1. Public Class Form1
  2.  
  3.   Private _buttons As List(Of Button)
  4.  
  5.   Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  6.     _buttons = New List(Of Button)
  7.     For i As Integer = 0 To 19
  8.       Dim btn As New Button
  9.       btn.Height = 20
  10.       btn.Width = 50
  11.       btn.Text = String.Format("{0}", i + 1)
  12.       btn.Name = String.Format("{0}{1}", "btn_", i + 1)
  13.       btn.Location = New Point(0, i * 20 + 5)
  14.       AddHandler btn.Click, AddressOf Button_Click
  15.       _buttons.Add(btn)
  16.       Me.Controls.Add(btn)
  17.     Next
  18.     Me.Height = 25 * 20
  19.   End Sub
  20.  
  21.   Private Sub Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
  22.     MessageBox.Show(String.Format("{0} {1}", CType(sender, Button).Name, "was clicked"))
  23.   End Sub
  24. End Class
-Frinny
Sep 15 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Matt | last post by:
How can I implement multiple buttons for a form like - submit, cancel, logout etc. Thanks. Matt
2
by: Matt | last post by:
The problem is I have 3 buttons that need to submit the form to different URL. My approach is to declare <input type="submit"> rather than <input type="button">. And put the following in the...
2
by: Matt | last post by:
The ASP page has multiple buttons, and when the user clicks different buttons, it will submit the form data to different URLs. My first approach was to use BUTTON type, and triggers javascript...
2
by: D | last post by:
Most of my web forms have multiple buttons (Proceed, Back, link buttons for various screens, etc.) It looks like, say a required field validator for example, gives me an error message no matter...
4
by: Dan Dautrich | last post by:
I'm trying to create a custom user control using VB.NET 2002 and ran across a stumbling block. I need an indefinite number of buttons to display across the control, based on its size. I'm not...
0
by: Rich | last post by:
HowDo I script multiple buttons on one scene/frame all with different scenes? Like a menu bar across the front. Please help
9
by: mosscliffe | last post by:
I am struggling to find a python example of the scenario - I have. I have a python script, which generates a page with a search button (actually an input field). The data from the above...
0
by: fperri | last post by:
Hi, I'm doing my first site in ASP.net. I have a form that has two list boxes where they can select a value in one and click a button to select and it moves it to the other listbox. I got this to...
3
by: brian210 | last post by:
I am currently trying to make a four question quiz. Each question is on a new page. There will be a previous button and a next button to take the user to the previous and next question respectively....
2
by: Audie7734 | last post by:
I am working on a program where I need to read files. I won't know how many buttons I need until run time. I can't figure out how to create a button class I can call at run time. Each button will...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.