none
visual basic in VS2019 winforms RRS feed

  • Question

  • I have form1 with 10 buttons(button1, button2, etc) On form2 I have 3 radiobuttons On form3 I have a textbox

    What I am trying to do is get the name of the button clicked in form1 joined by the name of the radiobutton selected in form2 and display them both in the textbox

    Thursday, December 19, 2019 6:39 PM

All replies

  • Use a property.

    George Frias - AWWshop, Wiki1978

    Thursday, December 19, 2019 7:13 PM
  • Hi

    Here is one of many ways to do it.

    Form1 code

    Option Strict On
    Option Explicit On
    Public Class Form1
      Public b, r As String
      Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Form2.Show()
        Form3.Show()
      End Sub
      Private Sub Button_Click(sender As Object, e As EventArgs) Handles Button1.Click, Button2.Click, Button3.Click, Button4.Click, Button5.Click, Button6.Click, Button7.Click, Button8.Click, Button9.Click, Button10.Click
        b = TryCast(sender, Button).Name
        Form3.TextBox1.Text = b & " " & r
      End Sub
    End Class


    Form2 code

    Public Class Form2
      Public started As Boolean = False
      Private Sub RadioButton1_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton1.CheckedChanged, RadioButton2.CheckedChanged, RadioButton3.CheckedChanged
        If Not started Then
          started = True
          Exit Sub
        End If
        Form1.r = TryCast(sender, RadioButton).Name
        Form3.TextBox1.Text = Form1.b & " " & Form1.r
      End Sub
    End Class

    Form3 code

    Public Class Form3
      Private Sub Form3_Shown(sender As Object, e As EventArgs) Handles Me.Shown
        TextBox1.Text = Form1.b & " " & Form1.r
      End Sub
    End Class


    Regards Les, Livingston, Scotland

    Thursday, December 19, 2019 7:22 PM
  • I found out how to do it. Thanks anyway.
    Thursday, December 19, 2019 10:38 PM
  • I found out how to do it. Thanks anyway.

    Hi

    Share your solution which could help someone else looking for similar help.


    Regards Les, Livingston, Scotland

    Thursday, December 19, 2019 10:54 PM
  • Hi,

    Have you solved this problem now? It seems that you have got your solution.

    Also,I think the above reply leshay provides can provide you with a great solution, have you tried it?

    If so, hope you can close this thread by marking the reply as answer as this will help others looking for the same or similar issues down the road.

    Inaddition, use  DirectCast(sender, Button).Name will make the intent clearer.

    Best Regards,

    Julie


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, December 20, 2019 5:15 AM
    Moderator
  • I found out how to do it. Thanks anyway.
    Greetings, by not providing your solution those here to help will sooner or later stop responding your your questions plus this will be frustrating for others who want the same or close to the same solution to this problem. In other words by not responding hurts both you and the community.

    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Friday, December 20, 2019 6:02 PM
    Moderator