?
Solved

vb2010 getting name values from multiple buttons

Posted on 2013-10-26
3
Medium Priority
?
445 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 2000 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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:…
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

762 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