You are on page 1of 10

Ring Documentation, Release 1.

The next screen shot after clicking on the button in each sub window.

51.2. Example 508


Ring Documentation, Release 1.3

51.3 Open_WindowAndLink() Function

We can use the Open_WindowAndLink() function to connect between the application windows, pass messages (call
methods) between the objects.
This function uses Meta-programming to define dynamic methods in the Caller Class to use the dynamic objects of
other windows that we create.
Example : (Uses the Form Designer)
First Window
1. https://github.com/ring-lang/ring/blob/master/applications/formdesigner/tests/twowindowspart5/firstwindowView.ring
2. https://github.com/ring-lang/ring/blob/master/applications/formdesigner/tests/twowindowspart5/firstwindowController.ring
Second Window
1. https://github.com/ring-lang/ring/blob/master/applications/formdesigner/tests/twowindowspart5/secondwindowView.ring
2. https://github.com/ring-lang/ring/blob/master/applications/formdesigner/tests/twowindowspart5/secondwindowController.ring

51.3. Open_WindowAndLink() Function 509


Ring Documentation, Release 1.3

In the next code for example (from FirstWindowController.ring)


The Open_WindowAndLink() will create an object from the SecondWindowController Class
Then will add the Method : SecondWindow(), IsSecondWindow() Methods to the FirstWindowController Class
Also will add the Method : FirstWindow(), IsFirstWindow() Methods to the SecondWindowController Class
So the SendMessage() method in FirstWindowController class can use the SecondWindow() method to access the
object.
This is more simple than using Last_Window(), Parent() and SetParentObject() methods.
class firstwindowController from windowsControllerParent

oView = new firstwindowView

func OpenSecondWindow
Open_WindowAndLink(:SecondWindowController,self)

func SendMessage
if IsSecondWindow()
SecondWindow().setMessage("Message from the first window")
ok

func setMessage cMessage


oView.Label1.setText(cMessage)

51.4 Objects Library Source Code

The library source code is very simple, You can check the source code files
https://github.com/ring-lang/ring/blob/master/extensions/ringqt/objectslib/objects.ring
https://github.com/ring-lang/ring/blob/master/extensions/ringqt/objectslib/subwindows.ring

51.4. Objects Library Source Code 510


CHAPTER

FIFTYTWO

USING THE FORM DESIGNER

In this chapter we will learn about using the Form Designer.


We can run the From Designer from Ring Notepad
From the Menubar in Ring Notepad - View Menu - We can Show/Hide the Form Designer window.

Also we can run the Form Designer in another window.


From the Ring Notepad - Tools Menu - Select the Form Designer.

511
Ring Documentation, Release 1.3

52.1 The Designer Windows

Toolbox : To select controls to be added to the window.


Properties : To set the properties of the active window or controls.
Design Region : To select, move and resize the window and the controls.

52.2 The Toolbox

We have many buttons.


Lock : We can use it to draw many controls of the same type quickly.
Select : We can use it to select a control in the Design Region
Controls Buttons : Select a control to be added to the window.

52.3 The Properties

When we select the window or one control, We will have the selected object properties.
Also In the properties window we have a combobox to select the active control.
Some properties provide a button next to the property value. We can click on the button to get more options.
When we select more than one control, We will have options for multi-selection

52.1. The Designer Windows 512


Ring Documentation, Release 1.3

52.4 Running Forms

When we save the form file (*.rform), The Form Designer will create two Ring files
The Controller Class
The View Class
For example, if the form file is helloworld.rform
The form designer will generate two files
helloworldcontroller.ring
helloworldview.ring
To run the program, Open the controller class file then click the Run button (CTRL+F5)

Tip: When you open a form using Ring Notepad, the controller class will be opened automatically, So we can press
(CTRL+F5) or click on the Run button while the form designer window is active.

52.5 Events Code

1. Just type the method name in the event property.

52.4. Running Forms 513


Ring Documentation, Release 1.3

(2) Then write the method code in the controller class.

52.5. Events Code 514


Ring Documentation, Release 1.3

In this example we write


func CloseWindow
oView.win.close()

Where inside the controller class, We uses the oView object to access the form.
Another Example :

52.5. Events Code 515


Ring Documentation, Release 1.3

The Event Code


func SayHello
oView {
LineEdit2.setText("Hello "+ LineEdit1.text() )
}

52.6 Keyboard Shortcuts

After selecting one or group of controls


Use the Arrows (Up, Down, Left and Right) to move them around.
Shift + the Arrows (Up, Down, Left and Right) to Resize the controls.
Del button to delete the controls.
CTRL+SHIFT+V to Duplicate the controls.

52.7 Menubar Designer

From the Window properties we can open the Menubar Designer

52.6. Keyboard Shortcuts 516


Ring Documentation, Release 1.3

52.8 Window Flags

From the Window properties we can open the Window Flags window.

52.8. Window Flags 517

You might also like