Difference between revisions of "Control created using the GUI Package"
m (Categorized) |
|||
Line 55: | Line 55: | ||
[[Category:Tutorials]] | [[Category:Tutorials]] | ||
[[Category:Controls]] | [[Category:Controls]] | ||
Revision as of 22:25, 29 October 2008
In this tutorial, we will show you how to create a new control in the GUI package of Visual Prolog step by step. First we will create a simple control, which will have some drawing in it. And then we will create a control as a container control, which will have a button and a drawing inside.
Download: Source files of the example project used in this tutorial.
New Control
Let us create a new project with the name newCustomControl. We also create a new form testForm and we will enter invocation of this form on FileNew. You can see more details about how to add a form here.
We need to create a new control. We can use the following steps:
- Select a package in the project tree, where a new control will be created.
- Run command File|New and choose Control as item, which will be created.
- Type some name for the control. In our case the name is firstCustomControl
- Click Create button, you will see attributes of new control. It is worth to keep them unchanged for the first time.
IDE will generate default code.
Now we can do some drawing in it. Please select in the project tree firstCustomControl.ctl, run command View|Code Expert and add onPaint event responder. IDE will generate default code, so we can insert some drawing in it. For example, the code can be:
predicates onPaint : drawWindow::paintResponder. clauses onPaint(_, Rectangle, GdiObject) :- GdiObject:drawTextInRect(Rectangle,"Hello", [vpiDomains::dtext_Center]).
Finally you can add the control to the form testForm. You can recall how to add a control here.
New Compound Control
Let us create a new control secondCustomControl using File|New command. In IDE Dialog Editor we can add a button inside the control. Thus the new control becomes a compound control. Actually we can add any other control inside the new control.
We will also add onPaint responder to add some drawing and add onPushButton responder to add some handing of the button click. For example, the code can be:
predicates onPaint : drawWindow::paintResponder. clauses onPaint(_, Rectangle, GdiObject) :- GdiObject:drawTextInRect(Rectangle,"Hello2", [vpiDomains::dtext_Center]). predicates onPushButton : button::clickResponder. clauses onPushButton(Source) = button::defaultAction() :- stdIO::write("Button ",Source:getText(), " has been clicked\n").
The second control is ready and we can add it to the form testForm. You can recall, how to add a control here.