I am very new to C++ and would like to know how to handle the following:

Let's say I have a button on a form. When the user clicks the button, a new textbox is created on the form. How can I add event handling for this new text box?

Regards
EM

Recommended Answers

All 5 Replies

Are you using MFC or Win32 or Winforms (.NET)?

Maybe its just me, but that strikes me as a strange thing to do. Far easier to just put a text box on a form at design time, and retrieve data out of it if the user enters any.

I am currently using Winforms. The application I am trying to build is basically a POC, so I am no sure whether C++ is the correct language to use and I am not sure whether my approach is correct.

The application will basically act as a front end for designing IPL label formats. Users must be able to add any amount of text fields, barcodes, lines, etc. to the label design. From there I can determine the exact position of these items, and generate the IPL code for export.

IPL can become very messy and if you don't work with it every day, it tends to take a lot of time to generate simple formats. I hope a design tool will make life easier.

You would need to write the event handlers themselves ahead of time, so you couldn't have the user pick their own once the control was created.
So here's a normal event handler "hookup":

this->panel1->MouseDown += gcnew System::Windows::Forms::MouseEventHandler(this, &Form1::panel1_MouseDown);

In your case you'd be creating "panel1" dynamically and so you'd already have to have premade_MouseDown() written out instead of panel1_MouseDown. So you'd have a statement like the above after you've created your object where you're hooking up your method to the control.

That's probably as clear as mud. You just have to do in code what the Winforms does for you when you double click on an event in the properties.

Do some searching for this topic under ASP.NET sites (or even in the ASP.NET forum here :) ) as I think this is more common occurrence in that domain.

Thanks. I will give it a try

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.