Basic Controls – 1

( Image, Label and Button )

We are continuing with Viva_HMG.hbp, Main.prg and Main.fmg. First, let’s enlarge our form: width: 650, height: 550; and then place an image: First click “image” button the toolbar of HMG-IDE, and then click anywhere in the form. This clicked point in the form, will be left upper corner of control; in this case : image. IDE always first places controls with its default values. Our image is 405 x 340 pixel size:

We need assign a size to image control so it can hold properly our image. We can manually set these values and assign name of image file:

Background color of our form didn’t well-matched with this image. Let’s change it to white:

In this step, if we run the program we will see like this :

The STRETCH option of IMAGE control allows assigning size values to the control other than original image sizes. In this case quality of image may decrease. We need also avoiding distortion too; that is keeping fixed aspect ratio of image.

By assigning same width / height values of form and image; we can use an image as back-ground image of form. But in this case we can’t place other control onto image: because controls must not be overlap to each other. Under certain circumstances system not obstructs this. But the beneath control can’t seen.

The LABEL control is an exception of this rule by TRANSPARENT option. If a label is transparent, the beneath control may be seen partially.

Let’s add a label to our form:

The big “A” symbol in the toolbar of IDE represent LABEL. First click this button and then top of our form:

The placeholder of LABEL is primitive situation for now. We have added a new and adjusted  both to our needs:


If we built and run our project after set these values, appearance will be like this:

Since two controls (labels) have been overlapped, constructing this “shadow” effect will be a few painful. You can edit .fmg file out of HMG, via any text editor when necessary.

Labels probably are most used controls in GUI programming. This control simply displays any text onto form. For xBase programmers we can say this is GUI counterpart of @ …,… SAY command. As all other GUI controls, we use coordinate system to indicate placement of control. In addition we can set size ( width, height ), back and fore color values, font properties and others as well as we need.

Labels also have ALIGNEMENT property with LEFT, RIGHT and CENTER option. In this sample used LEFT.

In addition, LABEL control supports ACTION event too. This means you can instruct a LABEL control to do an action when user clicked it; same as BUTTON.

Last control to use in this sample is button.

Beside menus, buttons are handy controls for doing an action when user clicked. Let’s see how :

The button for BUTTON in the IDE Tool Bar is this:

As precedents, one click to this button and another one to form, under image:

And two more :

Now we can tailor these buttons to our needs:

First let’s change names and captions given by IDE:

btnOpenFile, btnEditRec and btnExit to names and Open File, Edit Record and Exit to captions, consecutively:

It’s time to assign ACTIONs to this buttons.

MsgInfo( “Open File”) to ACTION of btnOpenFile

MsgInfo( “Edit Record”) to ACTION of , btnEditRec,

ThisWindow.Release to ACTION of btnExit.

And, RUN of course …

Test ACTIONs of buttons by clicking: first two will repeat the sentences in their captions via MsgInfo() function  and the last will terminate program. Yes, we are using RELEASE method to the main window for terminate running program, instead of QUIT or CANCEL commands.

That’s all for now !

Downloads source files

Data entry boxes

HMG Tutor 21 — Data-Controls II:

TEXTBOX, DATEPICKER, CHECKBOX, EDITBOX

The ‘data-version’ of these controls required the use of the following properties / methods to bound them to a database field:

Field Property: Stablishes the field that control is bounded to.
Refresh Method: Updates control content based on current field content.
Save method: Updates database file according control content.

#include "hmg.ch"

Function Main
DEFINE WINDOW Win_1 ;
   AT 0,0 ;
   WIDTH 640 ;
   HEIGHT 480 ;
   TITLE 'Tutor 21: Data-Bound Controls Test' ;
   MAIN ;
   ON INIT OpenTables() ;
   ON RELEASE CloseTables()

   DEFINE TOOLBAR ToolBar_1 BUTTONSIZE 100,30 FLAT RIGHTTEXT BORDER

      BUTTON TOP ;
         CAPTION '&Top' ;
         PICTURE 'primero.bmp' ;
         ACTION ( DbGoTop() , Refresh() )

      BUTTON PREVIOUS ;
         CAPTION '&Previous';
         PICTURE 'anterior.bmp' ;
         ACTION ( DbSkip(-1) , Refresh() )

      BUTTON NEXT ;
         CAPTION '&Next';
         PICTURE 'siguiente.bmp' ;
         ACTION ( DbSkip(1) , if ( eof() , DbGoBottom() , Nil ) , Refresh() )

      BUTTON BOTTOM ;
         CAPTION '&Bottom' ;
         PICTURE 'ultimo.bmp' ;
         ACTION ( DbGoBottom() , Refresh() )

      BUTTON SAVE ;
         CAPTION '&Save' ;
         PICTURE 'guardar.bmp' ;
         ACTION ( Save() , Refresh() )

      BUTTON UNDO ;
         CAPTION '&Undo' ;
         PICTURE 'deshacer.bmp' ;
         ACTION ( Refresh() )

   END TOOLBAR

   @  50,10 LABEL LABEL_1 VALUE 'Code:'
   @  80,10 LABEL LABEL_2 VALUE 'First Name'
   @ 110,10 LABEL LABEL_3 VALUE 'Last Name'
   @ 140,10 LABEL LABEL_4 VALUE 'Birth Date:'
   @ 170,10 LABEL LABEL_5 VALUE 'Married:'
   @ 200,10 LABEL LABEL_6 VALUE 'Bio:'

   @ 50,200 TEXTBOX TEXT_1;
            FIELD TEST->CODE ;
            NUMERIC ;
            MAXLENGTH 10

   @ 80,200 TEXTBOX TEXT_2;
            FIELD TEST->FIRST ;
            MAXLENGTH 30

   @ 110,200 TEXTBOX TEXT_3;
             FIELD TEST->LAST ;
             MAXLENGTH 30

   @ 140,200 DATEPICKER DATE_4 ;
             FIELD Test->Birth

   @ 170,200 CHECKBOX CHECK_5 ;
             CAPTION '' ;
             FIELD Test->Married

   @ 200,200 EDITBOX EDIT_6 ;
             FIELD Test->Bio ;
             HEIGHT 100

END WINDOW

Win_1.Text_1.SetFocus

ACTIVATE WINDOW Win_1

Return Nil

Procedure Refresh
   Win_1.Text_1.Refresh
   Win_1.Text_2.Refresh
   Win_1.Text_3.Refresh
   Win_1.Date_4.Refresh
   Win_1.Check_5.Refresh
   Win_1.Edit_6.Refresh
   Win_1.Text_1.SetFocus
Return

Procedure Save
   Win_1.Text_1.Save
   Win_1.Text_2.Save
   Win_1.Text_3.Save
   Win_1.Date_4.Save
   Win_1.Check_5.Save
   Win_1.Edit_6.Save
Return

Procedure OpenTables
   USE TEST
Return
Procedure CloseTables
   USE
Return

CheckButton

HMG Tutor 11

Button + CheckBox = CheckButton

The CheckButton control, acts like a checkbox, but looks like a button. Like buttons, It comes in two flavors: Text and Graphical.

@ 10,10 CHECKBUTTON CheckButton_1 ;
        CAPTION 'CheckButton' ;
        VALUE .F.

@ 50,10 CHECKBUTTON CheckButton_2 ;
        PICTURE 'Open.Bmp' ;
        WIDTH 27 ;
        HEIGHT 27 ;
        VALUE .F. ;
        TOOLTIP 'Graphical CheckButton'

#include "hmg.ch"
Function Main
DEFINE WINDOW Win_1 ;
   AT 0,0 ;
   WIDTH 400 ;
   HEIGHT 200 ;
   TITLE 'Tutor 11 - CheckButton Test' ;
   MAIN
   DEFINE MAIN MENU
      POPUP "First Popup"
         ITEM 'Change Text CheckButton Value' ACTION ;
               Win_1.CheckButton_1.Value := .T.
         ITEM 'Retrieve Text CheckButton Value' ACTION ;
               MsgInfo ( if(Win_1.CheckButton_1.Value,'.T.','.F.'))
         SEPARATOR
         ITEM 'Change Picture CheckButton Value' ACTION ;
               Win_1.CheckButton_2.Value := .T.
         ITEM 'Retrieve Picture CheckButton Value' ACTION ;
               MsgInfo ( if(Win_1.CheckButton_2.Value,'.T.','.F.'))
      END POPUP
   END MENU
   @ 10,10 CHECKBUTTON CheckButton_1 ;
           CAPTION 'CheckButton' ;
           VALUE .F.
   @ 50,10 CHECKBUTTON CheckButton_2 ;
           PICTURE 'Open.Bmp' ;
           WIDTH 27 ;
           HEIGHT 27 ;
           VALUE .F. ;
           TOOLTIP 'Graphical CheckButton'
END WINDOW
ACTIVATE WINDOW Win_1
Return

Getting Logical

HMG Tutor 5

Getting Logical

Sometimes, you need to get logical data. from the user. The easiest way to do that, is using a checkbox control.

@ 180, 120 CHECKBOX Check_1

We add it to the program, along with new menu options to set or retrieve its value.

#include "hmg.ch"
Function Main
DEFINE WINDOW Win_1 ;
   AT 0,0 ;
   WIDTH 400 ;
   HEIGHT 300 ;
   TITLE 'Tutor 05 - CheckBox Test' ;
   MAIN
   DEFINE MAIN MENU
      POPUP "First Popup"
        ITEM 'Change CheckBox Value' ACTION ;
              Win_1.Check_1.Value := .T.
        ITEM 'Retrieve CheckBox Value' ACTION ; 
              MsgInfo ( if(Win_1.Check_1.Value,'.T.','.F.'))
      END POPUP
   END MENU
   @ 100, 120 CHECKBOX Check_1 CAPTION 'Check Me!'
END WINDOW
ACTIVATE WINDOW Win_1
Return