473,322 Members | 1,614 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

how to get value from one form to another form and vice versa

I have two form in my project 1st form is FORM1 and 2nd form is FORM2.
FORM1 contain 3 textbox,1 button and FORM2 also contain 3 textbox, 1 button. I want to do....
when user fill FORM1 textboex and click button1 then all entries should be shown on FORM2. and vice versa plz help me.i used this code its working very good. when i pass value in form2 textboxes its show on form1 textbox. but i want to do, if textbox of form1 is already fill then form2 textboex should also shws form1 textbox value. plz help me
Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9.  
  10. namespace punchout
  11. {
  12.     public partial class Form1 : Form
  13.     {
  14.         public string RichText { get { return richTextBox1.Text; } set { richTextBox1.Text = value; } }
  15.         public string txtbox1 { get { return textBox1.Text; } set { textBox1.Text = value; } }
  16.         public string txtbox2 { get { return textBox2.Text; } set { textBox2.Text = value; } }
  17.         public string txtbox3 { get { return textBox3.Text; } set { textBox3.Text = value; } }
  18.         public Form1()
  19.         {
  20.             InitializeComponent();
  21.         }
  22.  
  23.         private void richTextBox1_Click(object sender, EventArgs e)
  24.         {
  25.             var form2 = new Form2(this);
  26.             form2.Show();
  27.         }
  28.     }
  29. }
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36. using System;
  37. using System.Collections.Generic;
  38. using System.ComponentModel;
  39. using System.Data;
  40. using System.Drawing;
  41. using System.Linq;
  42. using System.Text;
  43. using System.Windows.Forms;
  44.  
  45. namespace punchout
  46. {
  47.     public partial class Form2 : Form
  48.     {
  49.         private Form1 parentForm;
  50.  
  51.         public Form2(Form1 form)
  52.         {
  53.             InitializeComponent();
  54.             this.parentForm = form;
  55.         }
  56.  
  57.         private void Form2_Load(object sender, EventArgs e)
  58.         {
  59.  
  60.         }
  61.  
  62.         private void button1_Click(object sender, EventArgs e)
  63.         {
  64.             //if (this.parentForm == null)
  65.             //{
  66.                // return;
  67.             //}
  68.             parentForm.RichText = textBox1.Text + Environment.NewLine + textBox2.Text + Environment.NewLine + textBox3.Text;
  69.             parentForm.txtbox1 = textBox1.Text;
  70.             parentForm.txtbox2 = textBox2.Text;
  71.             parentForm.txtbox3 = textBox3.Text;
  72.             this.Close();
  73.         }
  74.     }
  75. }
  76.  
  77.  
Feb 23 '13 #1
3 1817
zmbd
5,501 Expert Mod 4TB
Please re-word that last paragraph.
It is not an easy read and I fear that you will not get the correct answer with the way it is worded. After two readings, even I am not sure exactly what you are asking for the code to do.
Feb 23 '13 #2
gvuksa
7
Expand|Select|Wrap|Line Numbers
  1. private void richTextBox1_Click(object sender, EventArgs e)
  2.          {
  3.              var form2 = new Form2(this);
  4.  
  5.              form2.textBox1.Text = this.textBox1.Text
  6.  
  7.              form2.Show();
  8.          }
  9.  
Feb 24 '13 #3
zmbd
5,501 Expert Mod 4TB
I think you mis-understand, not the code, the text of the question.
Feb 24 '13 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Larry | last post by:
I have a form that submits some js created data through a formmail script. One field of the form is a text box for the person's name. I'd like the subject line of the resulting email to be "Some...
4
by: GavMc | last post by:
Hello I am new to internet programming and wonder if anyone can help me with this.... I am trying to pass a hidden field value on a form into another field on the form so that it can then be...
1
by: damatoer | last post by:
I am having problems with attempting to filter a form based on criteria selected in a combo box from another form. I am attempting to have a user select a order number from a combo box that is...
5
by: Bernard Davis | last post by:
Hi, I need to pass the value held in a field in one form and have it appear in another form. I specifically don't want to have to refer to the original form name as it has passed, because I...
3
by: fh1996 | last post by:
Form.Owner and Form.Parent, what's the difference between them? Form.ShowDialog() and Form.Show(), when to use which? Form.Activated(), what does it mean when saying a Form is "activated"? ...
3
by: Brian Shannon | last post by:
Lets say I have web1.aspx which the user inputs data into txtData (text box). When the user clicks the button ADD the browser takes the user to web2.aspx. On web2.aspx I need to post the data...
9
by: AMBLY | last post by:
Hello ! Hope someone might be able to help me with this one. I run Access2000 on XP. I have a form : frmONE- which contains a txt field: ctrCTN from my table/database. The values in ctrCTN are...
1
by: kunohiko | last post by:
Greets all... need help on reading value from another form under the same project. for example, i have frm1 and frm2, in frm2, i gotta use back the frm1.txtbox1.text value, how should i handle...
5
by: prasannagodbole67 | last post by:
IN c# : how to get value from another form .......................................... In 1st form there is a textBox that textbox value i want to another form in label.......
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.