CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2004
    Location
    NH
    Posts
    678

    TextBox to TextBox?

    This must be a stupid question, but after an hour of trying it's now intelligent for me to ask.

    How would I sync a form's textbox, with the main form's textbox?

    When the user, click a button on the main form, another form loads up.
    Then when they change the textbox, I want a textbox in the main form to be updated with that string. Simple right!

    In the old VB6, this was completely trivial.
    It seems that .NET is not as easy, perhaps for protection?
    I tried delclaring the form, and texbox, but to no avail.


    At a loss,
    TT(n)

  2. #2
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    Re: TextBox to TextBox?

    Yes in VB6, it was easier!!

    Code:
    Public Class Form1
    Inherits System.Windows.Forms.Form
     
    Private F2 As New Form2 'F2 is now form2
     
    Private Sub TextBox1_LostFocus(ByVal sender AsObject, ByVal e As System.EventArgs) Handles TextBox1.LostFocus
     
    F2.TextBox1.Text = Me.TextBox1.Text 'set the text equal
     
    End Sub
     
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
     
    F2.Show() 'show the next form
     
    End Sub
     
    End Class



  3. #3
    Join Date
    Jun 2004
    Location
    NH
    Posts
    678

    Re: TextBox to TextBox?

    RESOLVED


    Thanks!

    This is about what I thought it should be.
    I was using Dim, instead of Private.

    Duh
    TTn



    At the VBforum I got this example, which works too but is a little more involved. Pretty cool though, this is also what I suspected if not trivial.

    Code:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            On Error Resume Next
            Dim fSound As New frmSound
            AddHandler fSound.txt.TextChanged, AddressOf ChangeHandler
    End Sub
    
    Private Sub ChangeHandler(ByVal sender As Object, ByVal e As EventArgs)
            Me.txt2.Text = DirectCast(sender, TextBox).Text
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured