关闭表格后保存价值,方法等

时间:2016-09-27 13:33:05

标签: c# winforms

所以基本上我有两种形式。在第一个我有标签,我用来显示计算值和一个显示Form2的按钮。表单2包含“保存按钮”和用于输入值的numericupdown控件。

问题是,如何通过按“保存按钮”将表格中的“数据”保存到适当的班级?

BaseForAll

class BaseForAll
{   //Class that im using as a "base class" for other classes 

    private decimal x;
    public decimal X
    {
        get
        {
            return x;
        }
        set
        {
            value = x;
        }
    }
}

baza2

class baza2:BaseForAll
{    // Calculating a value.
    private decimal Xs()
    {
        decimal resultOfX = X / 10;
            return resultOfX;
    }
    public decimal ResultOfXs
    {
        get
        {
            decimal resultOfXs = Xs();
            return resultOfXs;
        }
    }
}

窗体2

public partial class Form2 : Form
{

    baza Baza;
    public Form2()
    {
        InitializeComponent();
        Baza = new baza((decimal)numericUpDown1.Value);
    }



    private void button1_Click(object sender, EventArgs e)
    {
        this.DialogResult = DialogResult.OK;
    }

    private void numericUpDown1_ValueChanged(object sender, EventArgs e)
    {
        Baza.X = (decimal)numericUpDown1.Value;
    }
}

Form1中

public partial class Form1 : Form
{
     Form2 frm;
    baza2 Baza2 = new baza2();
    public Form1()
    {
        InitializeComponent();
    }


    private void button1_Click(object sender, EventArgs e)
    {
        Form1 form1 = new Form1();
        frm = new Form2();
        if (frm.ShowDialog() == DialogResult.OK)
        {
            /// ??????
        }

    }


    private void displaylabel()
    {
        decimal displayX = Baza2.ResultOfXs;
        label1.Text = displayX.ToString();
    }
}

巴扎

 class baza:BaseForAll
{
    public baza(decimal X)
    {
        this.X = X;
    }
}

1 个答案:

答案 0 :(得分:0)

您只需使用apps访问要访问的数据即可。在Form2和Form1中将变量更改为公共frm

public baza Baza;