Form 1 contains label1 and buttonOk (form1 NOT closed)
on buttonOk click the opens Form 2

Form 2 contiant a numericupdown and button1
on button1 click value of numericupdown should be displayed in label1


i tried to do this using the constructor and did not work.. help pls

Check this code

//Main form code 
String  receive="";
             private void buttonOnMain_Click(object sender, EventArgs e)
             {
                 msBox objms = new msBox();
                 objms.Show();
                 this.Hide();
             }
             public void set1(String val)
             {
                 receive= val;
             }

             private void buttonReceive_Click(object sender, EventArgs e)
             {
                 MessageBox.Show(receive);               

             }

//Message Box Code 
 Main mm = new Main();
        private void button1_Click(object sender, EventArgs e)
        { mm.set1(textBox1.Text);
             this.Close();
        }
        void msBox_FormClosing(object sender, System.Windows.Forms.FormClosingEventArgs e)
        {
            mm.Show();
        }

YOu can do it this way:

//form1:
        public Form1()
        {
            InitializeComponent();
            label1.Text = "";
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Form2 f2 = new Form2(this);
            f2.Show();
        }

        public void PassDataFromForm2(decimal value)
        {
            label1.Text = value.ToString();
        }

//form2:
        Form1 f1;
        public Form2(Form1 _f1)
        {
            InitializeComponent();
            this.f1 = _f1;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            f1.PassDataFromForm2(numericUpDown1.Value);
        }

You can do this also.

//form1:
        public Form1()
        {
            InitializeComponent();
            label1.Text = "";
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Form2 f2 = new Form2();
            f2.ShowDialog(this);
			label1.Text=f2.SendValue.ToString();
        }

        

//form2:
        public Form2()
        {
            InitializeComponent();
            label1.Text = "";
        }
		//Create your public property on form2
		private uint _sendValue;
		public uint SendValue()
		{
			get { return _sendValue;}
			set { _sendValue=Value;}
		}
        public Form2()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            SendValue=numericUpDown1.Value;
        }

Check this code

//Main form code 
String  receive="";
             private void buttonOnMain_Click(object sender, EventArgs e)
             {
                 msBox objms = new msBox();
                 objms.Show();
                 this.Hide();
             }
             public void set1(String val)
             {
                 receive= val;
             }

             private void buttonReceive_Click(object sender, EventArgs e)
             {
                 MessageBox.Show(receive);               

             }

//Message Box Code 
 Main mm = new Main();
        private void button1_Click(object sender, EventArgs e)
        { mm.set1(textBox1.Text);
             this.Close();
        }
        void msBox_FormClosing(object sender, System.Windows.Forms.FormClosingEventArgs e)
        {
            mm.Show();
        }

thx :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.