Need a suggestion on how to make a button do something.

K

Keith

Hello,

I have invested years and years into Visual Basic in Visual Studio and the
MS Office products. Now, I’m taking a look at Visual c++ looking at it with
Visual c++ Express 2008. It looks really promising. And there are some
significant improvements since my old copy of Visual Studio was purhased. I
have written many plain old c functions in the vc++ environment, and today
moved to a new step.

I created a project with a form, (same as I did in VB) and added a button
“button1†then I looked at the code that shows properties for button1 and
that is shown below…


this->button1 = (gcnew System::Windows::Forms::Button());
this->SuspendLayout();
//
// button1
//
this->button1->Location = System::Drawing::point(136, 23);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(89, 42);
this->button1->TabIndex = 0;
this->button1->Text = L"button1";
this->button1->UseVisualStyleBackColor = true;



So it looks like I can make button1 call a function or do something by using
OnClick, but it would be helpful to see some code that does something when
OnClick happens. Does the code build on the followng?

this->button1->OnClick ... ??? how do I do something here, ie call a function
or is there some other way…

Thank you for giving me a lead on where this might go next.

Keith
 
P

PvdG42

Keith said:
Hello,

I have invested years and years into Visual Basic in Visual Studio and the
MS Office products. Now, I’m taking a look at Visual c++ looking at it
with
Visual c++ Express 2008. It looks really promising. And there are some
significant improvements since my old copy of Visual Studio was purhased.
I
have written many plain old c functions in the vc++ environment, and today
moved to a new step.

I created a project with a form, (same as I did in VB) and added a button
“button1†then I looked at the code that shows properties for button1 and
that is shown below…


this->button1 = (gcnew System::Windows::Forms::Button());
this->SuspendLayout();
//
// button1
//
this->button1->Location = System::Drawing::point(136, 23);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(89, 42);
this->button1->TabIndex = 0;
this->button1->Text = L"button1";
this->button1->UseVisualStyleBackColor = true;



So it looks like I can make button1 call a function or do something by
using
OnClick, but it would be helpful to see some code that does something when
OnClick happens. Does the code build on the followng?

this->button1->OnClick ... ??? how do I do something here, ie call a
function
or is there some other way…

Thank you for giving me a lead on where this might go next.

Keith

Assuming you are working with a C++/CLI (CLR) project, you can create event
procedures for the button and place any code you want to execute in the body
of the desired event procedure, just as you would in VB.

As the Click event is the default for a button, you can double-click on the
button in design view to create the event procedure shell.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top