0

Alrighty. Here is my problem. I have just about everything done. I just need to take input from the form, and then use it in an algorithm in the second form. I have everything else written up, I just need to know how to connect the 2 so I can write up the last of the code. I've done some research, but none of it seems to go with what I'm trying to do.

Here is the main form.

namespace Airplanes
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void radioButton2_CheckedChanged(object sender, EventArgs e)
        {

        }

        private void Arrival_Click(object sender, EventArgs e)
        {
            ArrivalForm newForm;
            newForm = new ArrivalForm();
            newForm.ShowDialog();

        }

        private void Fuel_Click(object sender, EventArgs e)
        {
            Fuelform newForm2;
            newForm2 = new Fuelform();
            newForm2.ShowDialog();

        }

        private void Status_Click(object sender, EventArgs e)
        {


        }

        private void Items_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void NameBox_TextChanged(object sender, EventArgs e)
        {

        }

        private void FuelBox_TextChanged(object sender, EventArgs e)
        {

        }

        private void GateBox_TextChanged(object sender, EventArgs e)
        {

        }

        private void Singlebutton_CheckedChanged(object sender, EventArgs e)
        {

        }

        private void PrivateButton_CheckedChanged(object sender, EventArgs e)
        {

        }

        private void CommercialButton_CheckedChanged(object sender, EventArgs e)
        {

        }

    }
}

And here is the form I'm trying to connect to the main form.

namespace Airplanes
{
    public partial class Fuelform : Form
    {
        public Fuelform()
        {
            InitializeComponent();
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void Fuelform_Load(object sender, EventArgs e)
        {

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {

        }
    }
}

Thanks in advance for any answers.

4

2 回答 2

4

有几种方法......最简单的可能是通过新表单的构造函数传递数据。

FuelForm newForm2 = new FuelForm(myData);

然后更改 FuelForm 的构造函数:

public FuelForm(int myData)  // or whatever data type you need
{
    // Deal with myData
}
于 2012-11-28T03:23:11.340 回答
1

以源代码形式

 destinationForm df = new destinationForm ();
            df .myValue= "My Value";
            df .ShowDialog();

在目的地表格中

  private string destVariable;

     public string myValue
            {
                get { return destVariable; }
                set { destVariable= value; }
            }

那么您可以在目的地形式的任何地方使用 destVariable

于 2012-11-28T03:27:44.263 回答