Hi everybody,
i am newbie working on a small application using c# .net

problem:

i have two forms, form1 and fom2.
i have textbox in both forms.
when i click the submit button i want to get the value from a form1 textbox into the form2 textbox automatically.

code:

// in form2


private void textBox12_TextChanged(object sender, EventArgs e)
        {
            textBox12 = Admin_Calculator.textBox13.Text;
        }

Error:

An object reference is required for the non-static field, method, or property 'WindowsFormsApplication3.Form1.textBox13'

OR

is there any other alternative way to acheive this..
please help me with issue

How is your application set up?

Is Admin_Calculator the name of the Form or is it an instance of the form you have created? Do you create an instance of the form to show with the .Show() method?

Admin_Calculator is the name of the form from where i want to get the value into form2 textbox

To do what you're trying to do, you're probably going to need to create an instance of the Admin_Calculator class.

How do you open the forms right now? Do you click something on one of the forms that causes the other to open?

here's the code....

//FORM1

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;

using System.Data.SqlClient;



namespace WindowsFormsApplication3
{
    public partial class Admin_Calculator : Form
    {
        public Admin_Calculator()
        {
            InitializeComponent();
        }

        private decimal MultiplyNumbers(decimal number1, decimal number2)
        {
            return number1 * number2;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            decimal value1 = decimal.Parse (SPOT.Text);
            decimal value2 = decimal.Parse (textBox2.Text);
            decimal returnValue1 = MultiplyNumbers(value1, value2);
            textBox13.Text = returnValue1.ToString();
       

    }
}

}

------------------------------------

//FORM2

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 WindowsFormsApplication3
{
    public partial class Display_Calculator : Form
    {
        public Display_Calculator()
        {
            InitializeComponent();
        }

        private decimal MultiplyNumbers(decimal number1, decimal number2)
        {
            return number1 * number2;
        }


        private void button1_Click(object sender, EventArgs e)
        {
            decimal value1 = decimal.Parse(textBox12.Text);
            decimal value2 = decimal.Parse(textBox18.Text);
            decimal returnValue1 = MultiplyNumbers(value1, value2);
            textBox24.Text = returnValue1.ToString();
        }

        private void textBox12_TextChanged(object sender, EventArgs e)
        {
            textBox12 = Admin_Calculator.textBox13.Text;
        }
    }
}

these two forms are independent, there is no button on form1 which opens the form2...

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.