suman
suman

Reputation: 41

event handling for button click in visual c++

I want to retrive the data from a textfield on the click of a button.

Upvotes: 1

Views: 14264

Answers (2)

yashannamal
yashannamal

Reputation: 39

private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e)      
{           
    label1 -> Text= "Hello Yashan";  
}

this is ok

Upvotes: -1

Adam Holmberg
Adam Holmberg

Reputation: 7365

  1. Add a new project of type "Visual C++/CLR/Windows Forms Application" to your solution.

  2. Add a button and textbox to the designer.

  3. Double-click the button on the designer. This should take you to the form code, where an event handler will have been created and registered for you.

  4. In the body of that event handler, you may access the text field using its name from the design (the name is viewed/modified by right-clicking the item in the form designer and selecting "Properties").

Edit: I typically don't use C++ for Windows Forms applications, but this example seems to work:

 private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
             System::String^ txt = this->textBox1->Text;
             txt += " augmented";
             this->textBox1->Text = txt;
           }

Upvotes: 2

Related Questions