Personal C Sharp         by    famsoft.org

Home | Demonstrative Examples | PC# Methods | PC# Reference | Links

Using Controls

                                                                           You are welcomed to use our site for your web search.
                                                                    See the fine products advertised at the bottom of each page too.

                                      EXAMPLES ON  CONTROLS
                                      =====================

EXAMPLE 1: Let us start with a simple one. We'll create a button and a text field. If
the user enters "red", "green" or "blue" into the text field then clicks the button,
the button background color changes accordingly. If he enters any other phrase, the
button's background color turns yellow.
=========================================================================================
public class a : pcs {   

  public override void init() {
    base.init();
  }

  public override void setup() {    // All installations are done within this method

    cs="tf0";k=50;i=200;o=20;cm("i");
                                    // Install text field "tf0", positioned on the window
                                    // at point (0,50), width=200, height=20 (pixels)
    cs="bt0";cis="My Color Changes";k=-50;i=140;o=40;cls="S9y0";cm("i");
                                    // Install button "bt0", positioned at point(0,-50)
                                    // width=140, height=40, black txt in yellow backgrnd
  } 

  public override void update() {   // This method is called whenever an event takes place

    if ("bt0".Equals(cs)) {         // If button "bt0" has generated this event
      cs="tf0";cm("gu");            // Get latest update of text field "tf0" in (cus)
      os=cus.Substring(0,1);om("u");// Get 1st char of (cus) and covert it to U/C
      n="RGB".IndexOf(os);          // See if it was R,G,B or none of them
      if (n<0) cls="S9y0";          // If none of them select yello background color
      else if (n==0) cls="S9r0";    // If was "R" select red background color
      else if (n==1) cls="S9g0";    // If was "G" select green background color
      else if (n==2) cls="S9b0";    // If was "B" select blue background color
      cs="bt0";cm("sC");            // Call method cm() to set the color for "bt0"
      cs="tf0";cus="";cm("su");     // Erase tf0's text.
      cs="tf0";cm("sx");            // Turn the focus state of "tf0" on.
    }
  }
}
=========================================================================================
HOW TO WRITE, COMPILE AND RUN THE PROGRAM? See Example 1 in the General Examples list.
=========================================================================================
TUTORIAL:

(1) This program contains two news methods, the "setup()" and the "update() methods.
Method setup is where you request the creation of new controls, how they look and where
they should be. Method update() is called automatically whenever an event concerning one
of the controls you have created takes place.

(2) As you can see, you did not need to set delegates or to work with objects. Objects
for all the controls created are stored into PC# archives. Whenever you like to operate on
a specific control, you supply method cm() with the key name of the control assigned to
(cs) together with any other required data and select the method's mode which performs
the operation.

(3) INSTALLING CONTROLS: To install a control, you call cm("i") with the control's key name
and its installation data. The installation data are many, we'll list few of them here and
keep the rest for the coming examples. There are default values for most of the data.
Control's location and size are the only required data.

j,k = Horizontal and vertical locations of control's center relative to form's ceter.
i,o = Control's width and height.
cls = Control's foreground color code followed with its background color code.
fns = Font code for control's text.

Control locations are measured relative to form's center instead of the top left corner
of the form. This simplifies installation significally. You must have noticed that we
have not supplied the value for the horizontal position of either control (j). That was
because we wanted them to be centered into the Form horizontally, so (j=0) for both. We
also wanted them to be at equal distances from the center vertically, so we choosed (k=50)
for "tf0" and (k=-50) for "bt0".

 So, we have nicely centered controls into the form with maximum ease. The best of all
is that you can change the size of the form as you like while keeping controls at the
center without having to modify your code. If you still see no enough advantage in making
all measurments relative to the form's center, wait until we get into "Drawing" to see how
easy, coveniet and more scientific this method is.

                                             k
                                             |
                                      -ve j  |  +ve j
                                      +ve k  |  +ve k
                                             |
                               --------------+------------- j
                                             |
                                      -ve j  |  +ve j
                                      -ve k  |  -ve k
                                             |

(4) When the user clicks on the button "bt0", method update() is called with the following
information:

cs=bt0  To let the method knows which control has generated the event.
cus=""  The update string which is meaningless in the case of a button.
cui=0   The order of selected row which is also meaningless in the case of a button.

Method update() should be made of several blocks, one for each control which can generate
an event which we need to handle. In this example, the only control which can generate an
event is "bt0", so there is only one block.

(5) The text field "tf0" also generates an event which method update() can receive if
the user pushes the [Enter] key after typing his text. We could have handled this event
directly if we have included a block in method update() which starts with
"if ("tf0".Equals(cs)) {".  However, in this example we used the button click to indicate
that user's text is ready.

(6) We can always get tf0's latest update any time by calling cm("gu"). The term "getting
latest update" means different things for different controls. For a text field, it means
getting the text it contains and returning its value into the control update string (cus).
For a Combo Box it means getting the order of selected row and returning its value into
the control update integer (cui)

(7) We can also write into the text field programatically by method cm("su")  We have used
this feature to erase the text field with:

      cs="tf0";cus="";cm("su");     // erase tf0's text.

(8) We can also turn any control's focus on programatically by method cm("sx"). We have
done that to "tf0" at the end of the program in order to save user the time spent in
clicking into the text field each time he/she wants to write into it.

(9) Finally, we have been only checking the first char of user's entered text in order
to know which color he has selected. This was to make things simple. Sorry if this didn't
please you.
=========================================================================================

demo10.jpg

                        Example 1: Shows how to create, install and handle events of Controls.
 You may download the executable file for Example 1 at: http://mysite.verizon.net/vze1l4h6/examples/C1.exe

EXAMPLE 2: Let us now get further, we are going to use several controls with variety of
sizes, colors, fonts and texts. Here are what we need to do:
(a) Create a Combo Box which contains several items and a label to identify it.
(b) Create a text field with a button by its side. Whenever the user enters a string into
    the text field and clicks the button, the string is added to the items the Combo
    Box contains. The button label will be "Add". The text field will contain some default
    text at startup.
(c) Create another text field, also with a button by its side. Whenever the user
    enters a string into that text box and clicks the button, the string will be compared
    against all items the Combo Box contains, if a match was found, that item will be
    selected. The button's label will be "Select"
(d) Create a third button labled "Which Item is Selected". Whenever the user clicks this
    button, The last selected item of the Combo Box will be determined. Its text and order
    number will be displayed into an external dialog box.
=========================================================================================
public class a : pcs {

  public override void init() {
    base.init();
  }
  public override void setup() {

    j=400;k=300;cm("fs");               // Resize Form to (400,300) Pixels
    cs="bt0";cis="Add";j=120;k=100;i=90;o=30;cls="r0y0";
        fns="trbsui16";id=0;cm("i");    // bt0: location (120,100), dimensions (90,30)

    cs="bt1";cis="Select";j=120;k=50;i=90;o=30;cls="r0g7";fns="trbi16";id=2;cm("i");
    cs="bt2";cis="Which Item is Selected?";i=340;o=30;cls="b0r7";
       fns="trb16";id=3;cm("i");        
    cs="lb0";cis="Test ComboBox >";j=-110;k=-90;i=120;o=30;os="e";cls="r0s3";
       fns="tri11";id=-1;cm("i");
    cs="tf0";cus="Banana";j=-60;k=100;i=225;o=30;cls="b0p7";fns="trb16";id=4;cm("i");
    cs="tf1";cis="";j=-60;k=50;i=225;o=30;cls="S9b7";fns="tr16";id=5;cm("i");
    cs="ch0";cus="Select a fruit";j=80;k=-90;i=190;o=40;cls="b0m6";fns="trb16";
             CIS=new string[] {"Apples","Oranges","Peaches","Pears"};
             id=6;cm("i");
  } 

  public override void update() {

    if ("bt0".Equals(cs)) {              // If bt0 clicked
      cs="tf0";cm("gu");                 // Get tf0 update (its text) into (cus)
      CIS[0]=cus;cs="ch0";cm("sL");      // Add it to ch0's list.
    }
    if ("bt1".Equals(cs)) {              // if bt1 clicked
      cs="tf1";cm("gu");                 // Get tf1's update value (its text) into (cus)
      string text=cus;                   // Save (cus) temporarely
      cs="ch0";cm("O");                  // Make (chp) refers to ch0's object.
      int index = chp.FindString(text);  // Search it for tf1's text match
      cus="";cui=index;cs="ch0";cm("su");// update ch0 (make cui its selected index)
    }
    if ("bt2".Equals(cs)) {              // if bt2 clicked
      cs="ch0";cm("gu");string text=cus; // Get ch0 update (its selected text)
      os="Selected Item's Text: " + text + "\n" + "Index: " + cui;cm("d");
                                         //Display results in a dialog
    }
  }
}
=========================================================================================
HOW TO WRITE, COMPILE AND RUN THE PROGRAM? See Example 1 in the General Examples list.
=========================================================================================
TUTORIAL:
(1) You already know how controls are created within method setup() The only difference
in this example is that more setup items have been given values instead of acceping their
defaults. Those items are:

cis: Control's label. Necessary for buttons, labels and Check Boxes.

os:  Label alignment. Can be:    os="c":Align at Control's center which is the default.
     os="w":Align at left side of the Control.  os="e":Align at right side of the Control.

cus: (Optional) Update string. In case of a text field, if assigned a string value at
     installation, the string will appear into the field at startup as a default choice.
 
id:  Tab Index. When you push the tab key repeatedly, controls gain focus in an order
     which is determined by the value of (id) for each control. if (id<0) the control
     will never gain focus.

Here are all controls and the value assigned to (id) for each:

bt0:0  bt1:2  bt2:3  lb0:-1  tf0:4  tf1:5  ch0:6

So when you hit the tab key repeatedly, the controls will gain focus at the same
order as listed above and lb0 will be skipped.

(2) INSTALLING THE COMBO BOX: The combo box gives you the choice of either selecting one
item from its list or if you could not find an item that you like enter a new item in its
top box to make it your choice just like you do with text fields. Installing a Combo Box
requires the following additional setup items:

CIS[]: A string array which contains all selectable items.
cui:  (Optional) Index of selected item. If we like to supply user with a default
      selection,we supply this integer value.
cus:  (Optional) It can be also used as a default choice for the new item the user may
      choose. However, it can also be used as a title for the Combo Box like we did in
      this example.

REMARKS:
a) cus, cui are update var's, which means that they are mainly for getting user's entered
data back to the program. We include them in our setup data only when we like to supply
default selection for the user.

b) In the case of a Combo Box, whenever we like to supply default selection, we should
either supply (cus) or cui. This is because the user can either select an item from
list or enter a new item into the top box.

(3) In the first block of method update(); we have obtained the string (tf0) contains,
assigned it to CIS[] and called the method to add it to the list. Please note that CIS[]
is reset before the method return in modes "i" and "s".

(4) In the second block of method update(), we needed to search all ch0's selections to
see if any matchs the string which the user has entered into "tf1". If a match was found,
we needed to know the index of the matching item in order to make it the selected item.

Although C# can do this search for us, PC# does not get involved into this particular
feature, so we must do it on our own. We ask method cm() to supply us with a reference
to ch0's object which is kept in PC#'s archives. PC# responds by making the "present Combo
Box object reference" which you must know that its name is (chp) refers to "ch0". 
If you are wondering why the two letter base name of the combo box is "ch" instead
of "cb", it is because it was initially called "Choice" and the name "cb" is reserved for
the "Check Box".
=========================================================================================

demo11.jpg

     Example 2: Working with several controls
You may download the executable file for Example 2 at: http://mysite.verizon.net/vze1l4h6/examples/C2.exe

EXAMPLE 3: Let us now get further, We need to create two "Radio Button groups, two Check
box groups and two "List Box" sets. One set of "single selection type" and the other of
"multiple selection" type. Additionally we'll interpret the events received from them all
and display what they mean. We are going also to create two "Text Area" controls to use
for display.


public class a : pcs {

  public override void init() {
    base.init();
  }
  public override void setup() {

    cs="rb00";cis="rb00";j=-330;k=150;i=80;o=30;cls="b09s00";cm("i");  // 1st rb group
    cs="rb01";cis="rb01";j=-210;k=150;i=80;o=30;cls="b09s00";cm("i");
    cs="rb02";cis="rb02";j=-90;k=150;i=80;o=30;cls="b09s00";cm("i");

    cs="rb10";cis="rb10";j=-330;k=100;i=80;o=30;cls="b09s00";cm("i");  // 2nd rb group
    cs="rb11";cis="rb11";j=-210;k=100;i=80;o=30;cls="b09s00";cm("i");
    cs="rb12";cis="rb12";j=-90;k=100;i=80;o=30;cls="b09s00";cm("i");

    cs="cb00";cis="cb00";j=-330;k=20;i=80;o=30;cls="b09s00";cm("i"); // 1st cb group
    cs="cb01";cis="cb01";j=-210;k=20;i=80;o=30;cls="b09s00";cm("i");
    cs="cb02";cis="cb02";j=-90;k=20;i=80;o=30;cls="b09s00";cm("i");

    cs="cb10";cis="cb10";j=-330;k=-40;i=80;o=30;cls="b09s00";cm("i"); // 2nd cb group
    cs="cb11";cis="cb11";j=-210;k=-40;i=80;o=30;cls="b09s00";cm("i");
    cs="cb12";cis="cb12";j=-90;k=-40;i=80;o=30;cls="b09s00";cm("i");

    cs="ls0";ib=false;j=120;k=50;i=120;o=230;cls="S9p7";fns="trb16";// Single
             CIS=new string[] {"Item 0","Item 1","Item 2"};cm("i"); // Selection List

    cs="ls1";ib=true;j=290;k=50;i=120;o=230;cls="S9y7";fns="trb16"; // Multiple
             CIS=new string[] {"Item 0","Item 1","Item 2"};cm("i"); // Selection List

    cs="pn0";cds="s";cls="s90s90";o=100;cm("i");                    // Panel and 2 Text
    cs="ta0";ps="pn0";i=380;cds="w";cls="S9s9";fns="crb12";cm("i"); // Areas installed
    cs="ta1";ps="pn0";i=380;cds="e";cls="S9s9";fns="crb12";cm("i"); // into the panel.
  } 

  public override void update() {

    es=""+(char)13+(char)10;               // New Line code to be used later.
    if (cs.IndexOf("ls")<0) {              // If event is for buttons (Not Lists)
      ss="";                               // Initialize display string
      ss+="Activated Control: "+cs+es;     // Add event source to display string

      cs="rb0*";cm("gu");                  // Get update for rb group 0 (should be cui)
      ss+="FIRST RB GROUP:  cui="+cui+es;  // Add (cui) of rb group 0 to display string

      cs="rb1*";cm("gu");                  //  Repeat for rb group 1
      ss+="SECOND RB GROUP: cui="+cui+es;

      cs="cb0*";cm("gu");                  // Get update for cb group 0 (should be CUS[])
      ss+="FIRST CB GROUP:  CUS[ ]=";      // Scan CUS[] and add all its 3 items to
      for (int n=0;n<3;n++) ss+="  "+CUS[n];         // display string
      ss=ss+es;                            // Add new line code to display string.

      cs="cb1*";cm("gu");                  // Repeat with cb group 1.
      ss+="SECOND CB GROUP: CUS[ ]=";
      for (int n=0;n<3;n++) ss+="  "+CUS[n];
      ss=ss+es;

      cus=ss;cs="ta0";cm("su");            // Display the display string on text area ta0.
    }
    else {                                 // Else if event source is a List Box
      ss="";                               // Initialize display string
      ss+="Activated Control: "+cs+es;     // Add event source to display string.

      cs="ls0";cm("gu");                   // Get update for ls0 & add to display (should
      ss+="FIRST LIST:  cui="+cui+es;      // be cui since single selection list)

      cs="ls1";cm("gu");                   // Get update for ls0 & add to display (should
      ss+="SECOND LIST:  CUS[ ]=";         // be CUS[] since Multiple selection list)

      for (int n=0;n<3;n++) ss+="  "+CUS[n];
                                           // Add CUS[] contents to display string.
      ss=ss+es;                            // Add new line code to display string.

      cus=ss;cs="ta1";cm("su");            // Display the display string on text area ta1.
    }
  }
}
=========================================================================================
HOW TO WRITE, COMPILE AND RUN THE PROGRAM? See Example 1 in the General Examples list.
=========================================================================================
TUTORIAL:
The setup() method should be easy to follow. There are only few new things which need
explanation.

(1) GROUP NAMING: Radio buttons and Check Box groups are installed individually and their
events can be handled also individually, except that installing them as groups makes
programming easier, more convenient and less subject to errors. We can have upto 9 groups
in one program (numbered 0:8). Each group can be made of upto 10 buttons (numbered 0:9)
So, "rb36" is the 7th Radio Button of the 4th group and "cb00" is the first Check Box of
the first group. Group naming for Radio Buttons, Check Boxes and (as we'll see later)
Menu's are mandatory.

Group number 10 is reserved for PC# internal use. In general, key names for any control
or file must be in the range "xx0" to "xx89". They can be of 3 or 4 char's long except
for grouped items where names must be 4 char's long.

(2) You may have noticed that the color codes for all buttons are made of 6 char's. This
was because we wanted their background color to match the form's color and the easiest
way to accomplish this is making their background color transparent (opacity digit=0)
So we used the 3-char code for both background and foreground. Foreground colors should
be fully opaque (opacity digit=9)

(3) "List Box" controls are multi-item controls, so their installation should be very
similar to the installation of the "Combo Box" in the previous Example. One small
difference is that they can be made to accept either single selection like Combo Boxes
and Radio Buttons or multiple selections like Check Boxes. We use the boolean variable
(ib) to differentiate between the two.

(4) The text areas have not been installed directly into the form. They have been
installed into a panel and the panel is installed into the form. You may have noticed
that we have not supplied full location or size data for either Text Area or for the
Panel, we have used layout technique to guarantee keeping them at the bottom of the form.
This will be discussed in details in the next Example.

(5) RECEIVED EVENTS: As you already know, when the user clicks on a control or an item
of a control, method update() is called and supplied with the key name (cs) of the
control which has generated the event.

Normally, we use (cs) to get the control's latest update by calling cm("gu"). We have done
that with the lists and we coud have done that with the buttons individually, except that
we have a better choice for thr Radio Buttons and Check Box groups, we can get their group
update at once by using Wild Card names. For example we could get the combined update for
Radio Button group number 1 with:

     cs="rb1*";cm("gu");

 (6) Since Radio Button groups and (ls0) are single selection items, their update is the
index of their selected item in (cui). For Check Box groups and (ls1), their update is
array CUS[] with each row containing either "1" or "0" indicating that the item of the
same order as the row is "selected" or "not selected" respectively.

There is nothing else which needs to be explained, you must be able to read the program
code and fully understand it.


=========================================================================================

demo12.jpg

                                             Example 3: Radio Buttons, Check Boxes and Text Boxes
You may download the executable file for Example 3 at: http://mysite.verizon.net/vze1l4h6/examples/C3.exe

EXAMPLE 4: Let us now discuss some layout considerations. We will use the same form which
has been generated in Example 3 for the discussion.

TUTORIAL:
The layout tools available are:
==============================

a) SCROLLABLE PANELS: You can make a control or a group of controls occupy less space in
   the form by installing a scrllable panel of the necessary size then installing the
   control(s) into the panel.

b) SCROLLABLE FORM: You can make the entire form scrollable, so it can handle its contents
   regardless to its size.

c) MARGINS: When the scrollable form is reduced in size, some of the controls it contains
   may end with their borders touching the form's borders. You can avoid that by specifying
   a horizontal and vertical margins.

d) ANCHORE: We can allow C#'s layout manager to move each control slightly in one or more
   directions whenever it finds that necessary.

e) DOCKING: We can force a control to be placed at any of the forms 4 sides and keeps
   its place when the form is recised.

How to do it:
=============

a) To place controls on panels, see the setup() method of Example 3, where the Panel pn0
   was created and the two Text Areas ta0,ta1 have been installed into it. To make the
   panel scrollable, just add (ib=true;) to pn0's parameters.

b) To make the Form scrollable add at the top of method setup: ib=true;cm("fa");

c) SETTING MARGINS: To clear 20 pixels at both left and right borders and 30 pixels at
   both top and bottom borders of the form, add this statement also at the top of
   method setup: j=20;k=30;cm("fm");

d) SETTING THE ANCHOR: To set the Anchor for any control to "South East", include this
   with the rest of its parameters in method setup:  cas="se";
 
d) SETTING THE DOCKING: To set the Docking for any control to "East", include this
   with the rest of its parameters in method setup:  cds="e";
   If you like to dock to more than one direction, we suggest installing the control(s)
   into panels. This technique has been used in Example 3, when the Panel was docked
   to the south while the 2 Text Areas docked to east and west.

Now try:
=======
(1) Modify Example 3 program by adding at the beginning of method setup:
j=600;k=350;cm("fs");               // Recise Form to (600,350)
Notice that some areas at the right side and at the bottom of the form have been
clipped off.

(2) Now add (ib=true;) to pn0's parameters.
Notice the scroll bar which now appears at the bottom of the panel. It allows us to see
both Text Areas in full, while changing nothing to all other controls in the form.

(3) Now add this second statement at the top: 
ib=true;cm("fa");                    // Set AutoScroll property to true.
Notice that the form has 2 scroll bars now which enables us to see all controls. Look at
the right side, you will see that "ls1" ends exactly at the right border of the form.
    
(4) Now add this third statement:
j=20;k=30;cm("fam");                 // Set horiz & vertical margins of 20 & 30 pixels
Notice that "ls1" is not touching form's border anymore.
=========================================================================================

demo13.jpg

Exampl4: Step (1) Recising form

demo14.jpg

Example 4: Step (2)  Making panel Scrollable

demo15.jpg

Example 4: Step (3)  Turning Form's Auto-scroll on

demo16.jpg

Example 4: Step (4)  Adding margins to the Form

EXAMPLE 5: It is now the time for the new menu's.  We are going to create 3 menu groups.
The first one will be of type "MainMenu" and will be installed at the top of the form.
The Second one will be of type "ContextMenu" and will be installed at a specific location
within the form. The third one will be also of type "ContextMenu" and will be attached to
a button. Whenever you Right-Click the button, the menu appears.

public class a : pcs {
  public override void init() {
    bli=1;
    base.init();
  }
  public override void setup() {
    cs="mn03";cis="Display a Picture";         // Main menu. Start with creating sub-menu
       CIS=new string[] {"Draw as is at Form's Center","Make it Form's Background Image"};
       cm("i");                                // which contains items only (leaf menu)
    cs="mn02";cis="Display a Shape";           // Then create menu's which contain items
       CIS=new string[] {"Square","Circle","Hexagon","Text"};
       cm("i");                                // and "already created" sub-menu's if any
    cs="mn01";cis="Display a Dialog";          // Same rule applies.
       CIS=new string[] {"Open File Dialog","Save File Dialog","Font Dialog",
       "Color Dialog","Print Dialog"};
       cm("i");
    cs="mn00";cis="main Menu";ib=true;         // Finally create the root menu. (ib=true)
       CIS=new string[] {"mn01","mn02","mn03","Change Form's color"};
       cm("i");                                // indicates "Main Menu" type.
 
    cs="mn10";cis="Context-1";ib=false;        // Create context menu group "mn1". Only
       CIS=new string[] {"Item 0","Item 1","Item 2","Item 3"};
       cm("i");                                // root. It has no sub-menu's.
   
    cs="mn20";cis="Context-2";ib=false;        // Create context menu group "mn2". Also
        CIS=new string[] {"Red","Green","Blue"};
        cm("i");                               // made of one root menu only.
    cs="lb0";cis="My Menu Sets My Color";j=00;k=100;i=200;o=50;cls="S9y0";
       cms="mn20";cm("i");                     // Create label and attach "mn20" to it
   
  } 
  public override void update() {
    // Var's Used: g=menu group number  m=sub-menu number t=Item number
    // Example: If cs="mi031":  g=0, m=3, t=1
    if (cs.IndexOf("mi")!=0) return;            // Neglect all but Menu item events.
    os=cs.Substring(2,1);                       // Get Group number from (cs)
    om("ti");g=o;                               // Convert it to type (int)
    os=cs.Substring(3,1);                       // Get Menu number from (cs)
    om("ti");m=o;                               // Convert it to type (int)
    os=cs.Substring(4,1);                       // Get Item number from (cs)
    om("ti");t=o;                               // Convert it to type (int)
    cs="";                                      // Erase (cs)
    cls="s9";gm("sps");lf=460;of=30;gm("crf");  // Cover previous mesg with white paint
    cls="S9";gm("sps");                         // Return drawing pen's color to black
    fns="trb16";os="Received events concerning: menu group "+g+", menu "+m+",item "+t;
    gm("ctf");                                  // Display msg describing selection.
    bli=g+2;um("b");return;                     // Jump to where selection is executed.
  }
  public override void run() {
// -------------------------------------- Startup ---------------------------------------
    if (blp==1) {
      cms="mn00";cm("fmm");                     // Install main menu into form
      cls="s9";gm("sps");lf=400;of=30;gm("crf");// Draw white rect at center to write on
    }
// ------------------- Execution of Main Menu Group (mn0) Selections ---------------------
    else if (blp==2) {                          // menu group 0
      if (m==3 && t==0) {                       // If "Draw pix at center" selected
        fls="pix.jpg";gm("cid");                // call gm() at mode "Create Image & draw"
      }
      else if (m==3 && t==1) {                  // If "Make pix form's backgrnd Image" sl.
        ims="pix.jpg";cm("fi");                 // call gm() at mode "form image"
      }
      else if (m==2 && t==0) {                  // If "Draw Square" selected
        lf=of=300;gm("crd");                    // call gm(), md "create rect & draw"
      }
      else if (m==2 && t==1) {                  // If "Draw Circle" selected
        lf=of=300;gm("ced");                    // call gm(), md "create ellipse & draw"
      }
      else if (m==2 && t==2) {                  // If "Draw Hexagon" selected
        lf=6;of=300;gm("c=d");                  // Use "Create Equal sided Shape & draw"
      }
      else if (m==2 && t==3) {                  // If "Draw Text" selected
        fns="trb64";os="Hello World!";gm("ctf");// Use mode "Create text & fill"
      }
      else if (m==1 && t==0) {                  // If "Display Open File Dialog" selected
        cm("dfo");os="You have selected the file: "+os;cm("d");
      }                                         // Call cm(), mode "Dialogs-file-open"
                                                // Then display file selected.
      else if (m==1 && t==1) {                  // If "Display Save File Dialog" selected
        cm("dfs");os="You have selected the file: "+os;cm("d");
      }                                         // Call cm(), mode "Dialogs-file-save"
      else if (m==1 && t==2) {                  // If "Display Font Dialog" selected
        cm("dtf");os="You have selected the font: "+fnp.Name;cm("d");
      }                                         // Call cm(), mode "Dialogs-text-font"
                                                // Then display name of selected font
      else if (m==1 && t==3) {                  // If "Display Color Dialog" selected
        cm("dtc");os="You have selected the color: "+clp.Name;cm("d");
      }                                         // Call cm(), mode "Dialogs-text-color"
                                                // Then display HEX code of selected color
      else if (m==1 && t==4) {                  // If "Display Print Dialog" selected
        cm("dp");                               // Display the dialog
      }
      else if (m==0 && t==3) {                  // If "Change form's color" selected
        cls="b5";cm("fcb");                     // Change to light blue using mode:
      }                                         // "Form-color-background" of cm()
    }
// -------------- Execution of Form's Context Menu Group (mn1) Selections ---------------
    else if (blp==3) {                          // It does not include items to execute
    }
// --------------- Execution of lb0's Context Menu Group (mn2) Selections ---------------
    else if (blp==4) {
      if (t==0) cls="S9r0";                     // If item 0, select red backgrnd color
      else if (t==1) cls="S9g0";                // If item 1, select green backgrnd color
      else if (t==2) cls="S9b0";                // If item 2, select blue backgrnd color
      cs="lb0";cm("sC");                        // Then Call method cm() to set lb0 color
    }
// --------------------- Things to do at the end of each Selection -----------------------
    cms="mn10";j=-40;k=-80;cm("fmc");           // After executing every selection,
  }                                             // reinstall Context Menu
}
=========================================================================================
HOW TO WRITE, COMPILE AND RUN THE PROGRAM? See Example 1 in the General Examples list.
=========================================================================================
TUTORIAL:
(1) MENU NAMING: Naming menu groups is similar to naming Radio Button and Check Box groups.
We are allowed upto 9 menu groups (groups 0:8 ) and each group can contain upto 10
sub-menu's (menu's 0:9) Menu group 9 is reserved for PC# internal use.
The nenu group is a menu tree in which the root menu contains a combination of menu items
and sub-menu's. Each sub-menu also may contain items and other sub-menu's. For example
menu group number 3 may be made of a root menu "mn30", which may contain sub-menu "mn31"
and sub-menu "mn31" may contain sub-menu "mn32" and sub-menu "mn33" and so on. Number of
all menu's in the tree must not exceed 10 and their names should be "mn30":"mn39".
(2) MENU SETUP: Menu setup is made to be as simple as possible. It is made to be similar to
the setup of any other multi-item control with the following few additional rules:
a) If a menu contains a sub-menu among its items, the text for the item representing the
sub-menu will be the sub-menu's key name. For example "mn31" may contain two items
"Apples" and "mn32"
b) You can't include a sub-menu as an item of another menu unless that sub-menu has
already been created. So, concerning the example mentioned in (a), creation of
sub-menu "mn32" must preceed the creation of "mn31". 
c) Unlike all other controls, the only setup items available for menu's are their names
in (cis), their items in CIS[] and the boolian value (ib) which is described next.
d) There are two types of menu's, "Main" and "Context". Your program can include only
one main menu which is installed at the top of the form. However, your program can include
several context menu's which you can make appear at any location into the form or attach
to any control. Cotext menu's which are attached to controls, appears when the control is
right clicked. Context menu's disappear once selection is made while the main menu stays
at it's place all the time. To indicate that a menu is intended to be the main menu include
(ib=true) among the setup parameters of its root.
(3) RECEIVING EVENTS FROM MENU'S: The only events which interest us are the ones generated
when the user clicks on an item. As with all other controls, each menu item has its own
unique key name (cs) Immediately after the item is clicked on, method update is called and
supplied with (cs) for the item.
Key names for menu items are in the form "migmt". "mi" means "menu item", "g" is a digit
(0:8) representing the menu group the item belongs to, "m" is a digit (0:9) representing
the menu it belongs to and "t" is the order number of the item within its menu.
For example when item number 3 of menu "mn01" is clicked on, method update will be called
and supplied with (cs=mi013)
(4) Now look at method setup() of the example, every thing should be easy to understand.
Notice that "mn00" included (ib=true) since it is the root of the menu group which we
like to use as "Main menu". Also, notice that in the setup of "lb0", we included
(mns=mn20) which attaches context menu "mn20" to that control.
(5) Method update() seperates group number, menu number and item number from the key name
received, displays them at the center of the form graphically. This is the first time
this type of text display has been done. Notice how making measurments relative to form's
center has simplified things. We did not need to state where text should be displayed,
because if we did, it should have been (j=0;k=0;) which is the default, thanks to the
GUV's rules.
(6) Before displaying the new message, we had to erase old ones, so we drew and filled a
 white rectangle at the center to cover up old messages. Again see how easy it is to make
two different shapes, a string and a rectangle line-up perfectly without having to wory
about misalignment whenever the form is resized.
(7) Method run() is divided into blocks as normal, the first block is the start-up block
where main menu is installed into form. Each of the other blocks executes the selections
received from items of each menu group. At the end of method run(), the form's context
menu is reinstalled. This is necessary since context menu's last only until the user
pushes any key then they disappear.
=========================================================================================

demo17.jpg

Example 5: Creating Graphical menu's. Drawing 3 shapes and 1 image have been selected from Main Menu.
 Also Button's color has been changed to blue using its attached Context Menu
You may download the executable file for Example 5 at: http://mysite.verizon.net/vze1l4h6/examples/C5.exe
You'll also need to download the picture file "pix.jpg" at: http://mysite.verizon.net/vze1l4h6/examples/pix.jpg

demo18.jpg

Example 5: Creating Graphical menu's. Drawing text and changing Form's background color have been
selected from Main Menu
 

demo19.jpg

Example 5: Creating Graphical menu's. Installing background image int o Form have been selected from Main Menu.
Also Button's color has been changed to Green using its attached Context Menu

EXAMPLE 6: Mostly, every thing necessary concerning "Controls" has been covered in the
preceeding examples. The only two items which I believe have been missed are the
installation of "Tooltips" and "Background Images". Tooltips are the little yellow text
strips which appear when you place mouse cursor on a control for few seconds without
clicking. We are going to create a button with background image and a tooltip attached.
There will be no tutorial following this example.
public class a : pcs {
  public override void init() {
    base.init();
  }
  public override void setup() {
    cs="bt0";cis="Look at my Tooltip";i=250;o=100;fns="trb20";
       ims="pix.jpg";cts="WARNING: Do not click this button!";
       cm("i");             // Create button at center using the image in file "pix.jpg"
  }                         // as its background image and attach a tooltip to it.
  public override void update() {
    if (cs.Equals("bt0")) { // If "bt0" clicked
      ib=true;cm("fv");     // Make form invisible.
    }
  }
}
=========================================================================================
HOW TO WRITE, COMPILE AND RUN THE PROGRAM? See Example 1 in the General Examples list.
=========================================================================================
 

demo20.jpg

Example 6: Shaws how to add a tooltip to a control and how to tile it with a background image
You may download the executable file for Example 6 at: http://mysite.verizon.net/vze1l4h6/examples/C6.exe