Solved

Passing texbox values between forms

Posted on 2008-06-19
4
170 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

747 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now