Notes on Creating Controls

Controls can be created by BRE for you to use in your scripts. The functions provided in the bre20.child class make script writing simple. Instead of writing a 5-10 lines to create a control, all you need is one line (2 if you count the child assignment). Example:

        child romWind = (child)args[1];

        //make CheckBox
        CheckBox chk = romWind.CreateCheckBox(10,24,"Hello!!","Namespace.ClassName.chk_Click");
        
        //make LabeledText box
        LabeledText txt = romWind.CreateText(20,85,"Type Below",
                "Namespace.ClassName.txt_Change","ToolTip",70,LabeledText.LTMODEINT);

You must specify a handler function for most controls BRE creates for you. These handler fuction names are passed into the child (rom) window on object creation. Notice the Namespace.ClassName.txt_Change in the last example. It is the handler function for the LabeledText box.

Handlers are (instance, NOT static) funtions that are mapped to the most used event on that control. i.e. a check box handler are invoked when the checkbox changes from checked to unchecked or vise versa, a text box handler is fired when the text is changed (the user presses enter or leaves the text box (focus wise)), a Button clicked, etc.

The handler function definition from the last code example would then look like:

        //the params are:
        //args[0] = main window
        //args[1] = rom window (the child object)
        //args[2] = object that sent the event 
        //args[3] = event object (will be base class of EventArgs)
        public object txt_Change(params object[] args)
        {
                //do stuff here

                //you must return something.
                return null;
        }

Case IS important: NameSpace.Class.callme is NOT the same as namespace.cLass.calLme

Each time a control is created, the handler format is checked and it is made sure the function is really there. If either is bad, you will get a null instead of the created object.

Some of the objects created do not require a handler function. In this case you must pass in the namespace.class name so BRE knows who is creating the control. The namespace.class string is checked for validity and if the class doesnt exist, you will get a null object. GroupBoxes and top level MenuItems fall in this category.

None of the passed in string variables can be null except in the case of MenuItems. If any of them are, you will be returned a null object instead of your control. Also, if, for some reason, the creation process fails, you will get a null.

If you are looking for functionality the child class doesn't have, you can make your own dialog boxes or make your own GUI objects and have all the handler info in your script.


BRE Documentation Home