I have a form with form.cs file and another separate class file named car.cs. In my form I have a textbox named textbox1. Now in the separate class file I have defined a variable as follows with its property :
private string carMake;
public string CarMake
{
get { return carMake; }
set { carMake = value; }
}
how can I set carMake
value to the textbox1.text
value by the get and set methods.
Typically I data bind the domain object property to the Winforms control field. See Data binding for TextBox
Of course you can set it directly as well.
Example:
void buttonSave_Click(object sender, EventArgs e)
{
car.CarMake = textBox1.Value;
// ... save car object to database
}
public void SetValue()
{
car objCar=new car();
objCar.carMake=textbox1.Text;
}
just try this.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.