pass textbox value to another form
  • i have textbox in form1 and i want to pass it value two form2 textbox how i can i do this ?
  • 2 Comments sorted by
  • Vote Up0Vote Down WaqasWaqas
    172.00 Karma Accepted Answer
    hi here is many way but which shortest way i follow is that.
    make a static variable on form1 means your source form and assign value on it.and fetch value on form2 as destination form both form code is below.


    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;

    namespace CRSample
    {
    public partial class Form1 : Form
    {
    public Form1()
    {
    InitializeComponent();
    }
    public static string SetValueForText = "";
    private void button1_Click(object sender, EventArgs e)
    {
    SetValueForText = txt1.Text;
    Form2 frm = new Form2();
    frm.Show();
    }
    }
    }




    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;

    namespace CRSample
    {
    public partial class Form2 : Form
    {
    public Form2()
    {
    InitializeComponent();
    }

    private void Form2_Load(object sender, EventArgs e)
    {
    txt2.Text = Form1.SetValueForText;
    }
    }
    }

    another way is that you make property or class for get set values from one to another form.
  • thanks waqas code was simple and helpful.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, or you want to Ask a new Question, Please Login or Create a new Account by Clicking below

Login with Facebook

Tagged

Popular Posts of the Week

    Optimum Creative