Solved

vb2010 getting name values from multiple buttons

Posted on 2013-10-26
3
438 Views
Last Modified: 2013-10-26
At the moment, I have a button that sends a value to another form and displays result in a label. The problem is, I have 20 buttons that are labeled a to w that need to be coded and I am stumped as to how I can pass values from multiple buttons.

Would it be a case statement in the form being passed to? I am a new user to VB.Net and still finding my way so any help would be gratefully received. I have included code sample for the first button 'A'. Thanks

frmMain

Private Sub btnA_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles btnA.MouseDown
        If (e.Button = MouseButtons.Right) Then
            frmRacks.buttonName = "A"
            frmRacks.Show()
        ElseIf (e.Button = MouseButtons.Left) Then
            MessageBox.Show("To be coded")
        End If
    End Sub

Open in new window


frmRacks

Public Class frmRacks
    Public buttonName As String
    Private Sub racksfrm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        lblRacks.Text = buttonName

    End Sub

Open in new window

0
Comment
Question by:peter-cooper
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 28

Accepted Solution

by:
Ark earned 500 total points
ID: 39602486
Assuming form with buttons name is form1 and all buttons named btnX where X is letter from A to W
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        For Each ctrl In Me.Controls
            If TypeOf ctrl Is Button Then
                AddHandler CType(ctrl, Button).MouseDown, AddressOf btn_MouseDown
            End If
        Next
    End Sub

    Private Sub btn_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs)
        If (e.Button = MouseButtons.Right) Then
            Dim btn = CType(sender, Button)
            frmRacks.buttonName = btn.Name.Replace("btn", "")
            frmRacks.Show()
        ElseIf (e.Button = MouseButtons.Left) Then
            MessageBox.Show("To be coded")
        End If
    End Sub

Open in new window

0
 

Author Comment

by:peter-cooper
ID: 39602513
Hi Ark
Just on way out so will try later. Thanks very much
0
 

Author Closing Comment

by:peter-cooper
ID: 39602843
Thanks very much Ark.
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question