Solved

Passing texbox values between forms

Posted on 2008-06-19
4
173 Views
Last Modified: 2013-11-26
I am developing an application that when you click on an icon on the form, a text box populates another form which has a larger version of the same text box with a larger font to allow ease of editing.  After the editing is completed on the expanded text box, I want to pass the new text back to the original text box.  I can do it by hard coding the reference to the original text box in the expanded text box form but I would like to reuse the expanded textbox form on other text boxes and other forms within the application.  Any help greatly appreciated.
0
Comment
Question by:ameybusiness
  • 2
4 Comments
 
LVL 24

Expert Comment

by:mankowitz
ID: 21823611
Essentially, what you want to do is create a new form with a single, large text box that can be called up whenever you need it.

Add a handler for every textbox on your original form. (use the Enter event . When the user enters that text box, have it call up the larger text box at the same location as the current textbox. When the user leaves the new text box, make it invisible and copy the text property into the original text box.
0
 

Author Comment

by:ameybusiness
ID: 21824693
Thansk for the help.  
I got it working for one text box copying the text back to the original text box when I call the form_closing event.  My problem is I would like to re-create this for all text boxes on multiple forms.  Is there a way I can pass the form name and textbox name to the expanded form so that I can reference them when passing back the changed text - or is tehre an easier way to do this?
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 125 total points
ID: 21824791
Open the second form using ShowDialog().
This makes code STOP in the calling form until the dialog is closed.
To close the dialog, set the DialogResult property to OK or Cancel.
You can then check this value in the calling form and react accordingly.

Example:
Public Class frmEdit
 
    Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
        Me.DialogResult = Windows.Forms.DialogResult.OK
    End Sub
 
    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        Me.DialogResult = Windows.Forms.DialogResult.Cancel
    End Sub
 
End Class
 
Public Class Form1
 
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim fe As New frmEdit
        fe.TextBox1.Text = Me.TextBox1.Text
        If fe.ShowDialog = Windows.Forms.DialogResult.OK Then
            Me.TextBox1.Text = fe.TextBox1.Text
        End If
    End Sub
 
End Class

Open in new window

0
 

Author Closing Comment

by:ameybusiness
ID: 31468844
Worked perfectly.  I copied in to a function that I use in all of my forms.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

832 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