Home » U++ Library support » U++ Widgets - General questions or Mixed problems » Where to add event function in theide
|
|
|
Re: Where to add event function in theide [message #21478 is a reply to message #21473] |
Fri, 22 May 2009 10:26   |
 |
mirek
Messages: 14255 Registered: November 2005
|
Ultimate Member |
|
|
samsam598 wrote on Thu, 21 May 2009 21:22 | Thanks so much for your help.I mean,for example,when one clicks a button named btnOK,something happens:
void btnOK_Click()
{
PromptOK("Button btnOK is clicked.");
}
In the ide,when I create a form with a button,I can not find out where to add the above code.
ALT+T or Assist(ALT+C) all tried but it does not help.
Regards,
Sam
|
I see.
First of all, do you already have dialog class?
http://www.ultimatepp.org/reference$Layout.html
(beware, above example shows how to create your dialog class, not your case).
Anyway, as long as you have such class, simply put
myOKbutton = callback(btnOK_Click);
into constructor.
Note that in 99.99% cases, you will rather want to call a method of dialog, not global level function. That is what Alt+T is designed for. Also, as soon as you type THISBACK(, Assist++ will offer a list of methods...
Another relevant example:
http://www.ultimatepp.org/examples$Button.html
Just in this case, no layout is used. Anyway, using designed layout has very similar effect to adding "button" member variable and "Add(button.VCenterPos(20).HCenterPos(200));"...
Mirek
|
|
|
|
Re: Where to add event function in theide [message #21486 is a reply to message #21485] |
Fri, 22 May 2009 15:29   |
cbpporter
Messages: 1427 Registered: September 2007
|
Ultimate Contributor |
|
|
By using the Layout editor you create just a template, a recipe if you will, for creating a window or a widget that will have that layout and those fields. It is a definition, speaking in C terms. You need a declaration.
Let’s say you named your template TestLayout. Now you can create a concrete layout by appending "With" to the name of the template:
class testWindows: WithTestLayout<TopWindow>
Now you have a class with that layout and it will contain your "btnOK". Yet you can search in the code and you won’t find that explicit declaration anywhere.
In one of your methods from the class, usually the constructor, you can say:
btnOK=callback(btnOKClick);
Or if you want to use a less OOP approach, you can do:
WithTestLayout<StaticRect> b;
b.btnOk=callback...
Notice this time I used StaticRect. You can apply the layout to anything you want, including Buttons, EditFields and every existing widget, including your own if you have written any custom widgets.
PS: Don't forget to call CtrlLayout. Without it you layout will appear null.
I hope you’ll have more success with layouts in the future. Very powerful once you get used to them.
|
|
|
|
|
|
Goto Forum:
Current Time: Sun Apr 27 22:29:53 CEST 2025
Total time taken to generate the page: 0.01415 seconds
|