Solved

vb2010 getting name values from multiple buttons

Posted on 2013-10-26
3
405 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
  • 2
3 Comments
 
LVL 27

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now