how to clear textbox with Clear() method

Andrew 1 Reputation point
2021-03-07T02:59:12.707+00:00

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
Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
1,871 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Andrew 1 Reputation point
    2021-03-07T03:52:44.747+00:00

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

    0 comments No comments