В дочерней форме создаем свойство, которому будет присвоено значение из родительской формы.
В родительской форме присваиваем значение полю.
Передать данные можно только один раз, в момент создания дочерней формы.
В родительской форме присваиваем значение полю.
Передать данные можно только один раз, в момент создания дочерней формы.
Counter.cs
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;namespace_0022 {-
classCounter { -
ushortshowStart; -
ushortshowEnd; -
decimalprice; -
publicCounter(stringarg0,stringarg1,stringarg2) { -
ushort.TryParse(arg0,outshowStart); -
ushort.TryParse(arg1,outshowEnd); -
decimal.TryParse(arg2,outprice); -
} -
publicushortResultShow() { -
return(ushort)(showEnd - showStart); -
} -
publicdecimalSum() { -
returnMath.Round((decimal)(ResultShow() * price) , 2); -
} -
} }
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;namespace_0022 {-
classCounter { -
ushortshowStart; -
ushortshowEnd; -
decimalprice; -
publicCounter(stringarg0,stringarg1,stringarg2) { -
ushort.TryParse(arg0,outshowStart); -
ushort.TryParse(arg1,outshowEnd); -
decimal.TryParse(arg2,outprice); -
} -
publicushortResultShow() { -
return(ushort)(showEnd - showStart); -
} -
publicdecimalSum() { -
returnMath.Round((decimal)(ResultShow() * price) , 2); -
} -
} }
Form2Child.cs
usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingSystem.Windows.Forms;namespace_0022 {-
publicpartialclassForm2Child : Form { -
//создаем свойство, которому будет присвоено значение из родительской формы -
publicTextBox TextBox3Price { -
set{ -
textBox3 = value; -
} -
get{ -
returntextBox3; -
} -
} -
publicForm2Child() { -
InitializeComponent(); -
} -
privatevoidbutton1_Click(objectsender, EventArgs e) { -
//вычисляем сумму -
Counter C =newCounter(textBox1.Text, textBox2.Text, textBox3.Text); -
textBox4.Text = C.Sum().ToString(); -
} -
privatevoidbutton2_Click(objectsender, EventArgs e) { -
//кнопка Очистить очищает все текстовые поля -
foreach(Control iinControls) { -
if(i.GetType() ==typeof(TextBox)) { -
i.Text =string.Empty; -
} -
} -
} -
} }
usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingSystem.Windows.Forms;namespace_0022 {-
publicpartialclassForm2Child : Form { -
//создаем свойство, которому будет присвоено значение из родительской формы -
publicTextBox TextBox3Price { -
set{ -
textBox3 = value; -
} -
get{ -
returntextBox3; -
} -
} -
publicForm2Child() { -
InitializeComponent(); -
} -
privatevoidbutton1_Click(objectsender, EventArgs e) { -
//вычисляем сумму -
Counter C =newCounter(textBox1.Text, textBox2.Text, textBox3.Text); -
textBox4.Text = C.Sum().ToString(); -
} -
privatevoidbutton2_Click(objectsender, EventArgs e) { -
//кнопка Очистить очищает все текстовые поля -
foreach(Control iinControls) { -
if(i.GetType() ==typeof(TextBox)) { -
i.Text =string.Empty; -
} -
} -
} -
} }
Form1.cs
usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingSystem.Windows.Forms;namespace_0022 {-
publicpartialclassForm1 : Form { -
publicForm1() { -
InitializeComponent(); -
} -
privatevoidbutton1_Click(objectsender, EventArgs e) { -
Form2Child F2 =newForm2Child(); -
//присваиваем значение свойству дочерней формы -
F2.TextBox3Price.Text = textBox1.Text; -
//вызываем дочернюю форму -
F2.ShowDialog(); -
} -
privatevoidbutton2_Click(objectsender, EventArgs e) { -
//кнопка Очистить очищает все текстовые поля -
textBox1.Clear(); -
} -
} }
usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingSystem.Windows.Forms;namespace_0022 {-
publicpartialclassForm1 : Form { -
publicForm1() { -
InitializeComponent(); -
} -
privatevoidbutton1_Click(objectsender, EventArgs e) { -
Form2Child F2 =newForm2Child(); -
//присваиваем значение свойству дочерней формы -
F2.TextBox3Price.Text = textBox1.Text; -
//вызываем дочернюю форму -
F2.ShowDialog(); -
} -
privatevoidbutton2_Click(objectsender, EventArgs e) { -
//кнопка Очистить очищает все текстовые поля -
textBox1.Clear(); -
} -
} }