Solved

Passing texbox values between forms

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
vb.net class 3 22
how to check group permission on a file located on a remote server ? 3 24
Add a Condition in ASP Repeater 6 34
Why use this lambda? 12 38
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

827 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