Hopefully a simple multiple form question

PSU_Justin

Newcomer
Joined
Feb 24, 2003
Messages
19
Location
State College, PA
If I am working with two forms and I want to click a radiobutton on Form 2, how can I get that radiobutton control to place a numeric value into a textbox on Form 1?

I've tried this code unsuccessfully (only with a button instead of a radiobutton).

Visual Basic:
 Public Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim main As New Form1()
        Me.Close()
        main.nbox.Text = n

    End Sub
 
This is what I use to do:

Set the project to start at the Sub Main, then create a class and put this code in:
Visual Basic:
Public Class Class1
    Public Shared f1 As Form1 = Form1.ActiveForm
    Public Shared Sub Main()
        f1 = New Form1()
        f1.Show()
        Application.Run()
    End Sub
End Class

Then on the form2 you can reference the form1 through the class1:
Visual Basic:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Class1.f1.Text = TextBox1.Text
        Me.Close()
    End Sub

Hope this will help.
 
Right click on your project in the solution explorer and choose Properties. There you´ll find the item 'Startup Object', just choose 'Sub Main'.

The Apllication.Run is used to start the application from outside the form.
 
Back
Top