Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
ASP.NET
VB.Net
C-Sharp
SQL Server
 

How you can make one Click Event of Different Buttons.

Author: DevASP
Download Source Code : 353_Single_Event.zip

This is a Tip for Programmers that how they can Handle single Event for different Buttons and how to differentiate between events

Create a windows application then drag 10 buttons on from and arrange them now you just write this simple code. On Form Load Event:

 

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

 

        Button1.Text = "btn1"

        Button1.BackColor = Color.Red

 

        Button2.Text = "btn2"

        Button2.BackColor = Color.White

 

        Button3.Text = "btn3"

        Button3.BackColor = Color.Gainsboro

 

        Button4.Text = "btn4"

        Button4.BackColor = Color.Honeydew

 

        Button5.Text = "btn5"

        Button5.BackColor = Color.Aqua

 

        Button6.Text = "btn6"

        Button6.BackColor = Color.Beige

 

        Button7.Text = "btn7"

        Button7.BackColor = Color.CadetBlue

 

        Button8.Text = "btn8"

        Button8.BackColor = Color.DarkBlue

 

        Button9.Text = "btn9"

        Button9.BackColor = Color.Firebrick

 

        Button10.Text = "btn10"

        Button10.BackColor = Color.Gainsboro

 

    End Sub

 

  • Now write code on Button1 Click Event

 

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click, Button2.Click, Button3.Click, Button4.Click, Button5.Click, Button6.Click, Button7.Click, Button8.Click, Button9.Click, Button10.Click

        Select Case sender.text

            Case "btn1"

                Me.BackColor = Color.Red

 

            Case "btn2"

                Me.BackColor = Color.White

 

            Case "btn3"

                Me.BackColor = Color.Gainsboro

 

            Case "btn4"

                Me.BackColor = Color.Honeydew

 

            Case "btn5"

                Me.BackColor = Color.Aqua

 

            Case "btn6"

                Me.BackColor = Color.Beige

 

            Case "btn7"

                Me.BackColor = Color.CadetBlue

 

            Case "btn8"

                Me.BackColor = Color.DarkBlue

 

            Case "btn9"

                Me.BackColor = Color.Firebrick

 

            Case "btn10"

                Me.BackColor = Color.Gainsboro

        End Select

End Sub

This is a trick by which you can minimize yours functions.

 

Article Comments
Very Good Code.

Posted on 5/23/2010 1:01:23 AM by Shivnath Karmakar

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< How to make use of clipboard in Visual Basic.Net

Disclaimer - Privacy
© 2002-2017 DevASP.net