Click here to Skip to main content
15,919,341 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have a textbox and a button on a form1.

When the form loads and you click the button form2 loads which has another textbox and button on that form.
When I type some text in the textbox and click the button the text does not display on the form1 textbox.

I am using property approach.

Please help
Posted
Updated 21-Aug-10 6:59am
v2
Comments
Dalek Dave 21-Aug-10 12:59pm    
Minor Edit for Readability and Grammar.

You need to retrieve the contents of the form2 TextBox control before form2 is disposed. To do that, you have to handle the Closing event for form2 inside form1. In that event handler, you simply use your property to retrieve the contents of the Form2.TextBox, and do whatever you need to with it.
 
Share this answer
 
Comments
.NetDeveloper09 21-Aug-10 8:07am    
can you display some code here please how to doit.
#realJSOP 21-Aug-10 16:37pm    
I would, but I don't do VB - not because I can't, but because I choose not to.
.NetDeveloper09 22-Aug-10 5:03am    
please give me some coded example in C# or any other language you work, i believe in every language is the same just give me the code and i will convert it by myself into vb. i can work in C# and many other languages the same as much i am working in vb, please give me the code.
Maybe this would help a little

<pre lang="vb">

Public Class Form1

    Dim frm2 As Form2

    Private Sub btnShowForm2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnShowForm2.Click
        InitForm()
    End Sub

    Private Sub InitForm()

        If frm2 Is Nothing OrElse frm2.IsDisposed = True Then
            frm2 = New Form2
        End If

        If frm2.Visible = False Then
            frm2.Show()
        End If

    End Sub

    Private Sub btnSayHello_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSayHello.Click
        InitForm()
        frm2.SayHello(txtName.Text)
    End Sub

    Private Sub btnSetValue_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSetValue.Click
        InitForm()
        frm2.SampelValue = txtValue.Text
    End Sub

    Private Sub btnGetValue_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGetValue.Click
        InitForm()
        txtValue.Text = frm2.SampelValue
    End Sub
End Class



<pre lang="vb">Public Class Form2

    Public Sub SayHello(ByVal name As String)
        lblHallo.Text = "Hello " & name
    End Sub

    Public Property SampelValue() As String
        Get
            Return txtValue.Text
        End Get
        Set(ByVal value As String)
            txtValue.Text = value
        End Set
    End Property

End Class



This is something i picked up a while ago. I hope it helps

regards Zeldacat
 
Share this answer
 
Comments
Dalek Dave 21-Aug-10 13:00pm    
Good answer.
Hi my code is this:

VB
Public Class Form1

    Public _form2 As Form2 = New Form2

    Private Sub btnList_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnList.Click
        _form2.Show()

    End Sub

    Public WriteOnly Property _textBox() As String

        Set(ByVal Value As String)

            tbxVal.Text = Value

        End Set

    End Property


End Class

VB
Public Class Form2

    Public _form1 As Form1

    Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
        Dim frm As Form1 = New Form1
        'frm._textBox = _textBox1
        Value = _textBox1
        'frm.Close()
        Me.Close()
        'frm.Show()

        '_form1 = New Form1
        'With _form1
        '    .tbxVal.Text = _textBox1
        '    Me.Close()
        'End With


    End Sub

    Public ReadOnly Property _textBox1() As String
        Get
            Return tbxValue1.Text
        End Get
    End Property

    Private Sub Form2_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        Dim fm As Form1 = New Form1
        fm.tbxVal.Text = Value
    End Sub

End Class
 
Share this answer
 
v2
Comments
Dalek Dave 21-Aug-10 13:01pm    
Edit to Correct Code Block

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900