question

Andrew-7453 avatar image
0 Votes"
Andrew-7453 asked ·

how to clear textbox with Clear() method

Learning Visual C++ using Win Forms and VS 2019. Created a Win Forms with two textboxes and a single button. texbox1 is an input box and textbox2 echoes text box1 input. When button is clicked, I want the event to clear textbox1 using the Clear() method. Code snippet below. Problem is that Clear() is a method of TextBoxBase class and not TextBox class. I thought that TextBox class in inherited TextBoxBase class and I could simply use textBox1.Clear() because textBox1 is an object of TextBox class but that is not correct. Would appreciate any help. Thank you

 private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
     textBox1.Clear();

}
private: System::Void textBox1_TextChanged(System::Object^ sender, System::EventArgs^ e) {
textBox2->Text = textBox1->Text;
}

windows-forms
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

Andrew-7453 avatar image
0 Votes"
Andrew-7453 answered ·

was using incorrect syntax: changed to textBox1->Clear(); and it's working

·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.