1

So basically i have two forms. In the first one i have label that I am using to display calculated value and a button that shows Form2. Form 2 contains "save button" and numericupdown control that is used to enter a value.

The question is, how to save "data" in a form by pressing "save button" and then pass them to a proper class?

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;
        }
    }
}

Form2

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();
    }
}

baza

 class baza:BaseForAll
{
    public baza(decimal X)
    {
        this.X = X;
    }
}
Bassie
  • 9,529
  • 8
  • 68
  • 159
Allonder
  • 11
  • 1
  • 1

1 Answers1

0

You can just access the data you want to access using frm. Change your variable to public public baza Baza; in Form2, and in Form1:

if (frm.ShowDialog() == DialogResult.OK)
{
     baza b=frm.Baza;
}
Pikoh
  • 7,582
  • 28
  • 53