У меня есть пользовательский элемент управления, и на них много текстовых полей. Я добавляю этот элемент управления к другому проекту, и я могу его использовать, когда я пишу каждое свойство в UserControl. Я хочу установить поля текстового поля этого пользовательского элемента управления с помощью класса. Это мои коды:
Класс:
namespace IEUserControl
{
public class IEValue
{
public string IsEmriNo { get; set; }
public string Nevi { get; set; }
public string BrutKg { get; set; }
public string NetKg { get; set; }
}
}
Пользовательский контроль:
namespace IsEmriUserControl
{
public partial class UC_IsEmri : UserControl
{
public UC_IsEmri()
{
InitializeComponent();
}
//private IsEmriValue _isEmri;
//public IsEmriValue isEmri
//{
// get
// {
// return _isEmri;
// }
// set
// {
// _isEmri = value;
// }
//}
public string IsEmriNo
{
get { return txtIsEmriNo.Text; }
set { txtIsEmriNo.Text = value; }
}
public string Nevi
{
get { return txtNevi.Text; }
set { txtNevi.Text = value; }
}
public string BrutKg
{
get { return txtBrutKg.Text; }
set { txtBrutKg.Text = value; }
}
public string NetKg
{
get { return txtNetKg.Text; }
set { txtNetKg.Text = value; }
}
}
}
Когда я использую свойства, я могу установить значения текстового поля. Однако я хочу установить мои значения текстового поля в свой класс. Может ли кто-нибудь дать мне пример установки значений текстового поля с помощью класса? Спасибо.
Сделайте способ/свойство, подобное этому
public IEValue IE_Value
{
get
{
return new IEValue() {
IsEmrino = txtIsEmriNo.Text,
Nevi = txtNevi.Text,
BrutKg = txtBrutKg.Text,
NetKg = txtNetKg.Text
};
}
set
{
txtIsEmriNo.Text = value.IsEmrino;
txtNevi.Text = value.Nevi;
txtBrutKg.Text = value.BrutKg;
txtNetKg.Text = value.NetKg;
}
}