Session #

An Introduction to Controls

Rainer Becker

Controls.doc 37 KB

Controls.ppt 129KB


Abouüt the Speaker

Rainer Becker is the leader of the German FoxPro User Group, an organisation with 1100+ paying members (companies and programmers), and the president of the ISYS GmbH, a MS Solution Provider and contract partner of MS Consulting Services. You can reach him at:

Adress:          Rainer Becker, Messerschmittstr. 2a,

                       65760 Eschborn, Germany

                       Phone: 01149-6173-68182, Fax: -65997

But better you try it via CompuServe (CIS-ID 100024,1364) or leave a message at the dFPUG-section (GO MSCESYS).

Whats included

We will start with a short introduction to the principles of Properties, Events and Methods. You need to know these terms to work with controls of any kind.

The main part is a guided tour through all Controls. We will visit old, new and changed ones in a sorted order - walking all properties upstairs. The controls are sorted by the number of properties, events and methods they have bringing us some new of each by each new control we see.

Finally I will loose some words about containers, naming conventions and the use of Builders as well as guide you to some sessions that build on this one.

Whats excluded

We can not talk (at least not to much) about the following themes in Visual FoxPro:

    Form Designer
    Class Designer
    Non-Visual Objects

But you might get a good base for all of that with this session as you should have a good overview  over all types of controls.


Visual FoxPro introduces a lot of new buzz-words. Some of them are really important when you start working with controls. These are properties, events and methods. All three are not that exactly defined and overlap sometimes. The questions we need to answer in the beginning:

  • What are Properties ?
  • What are Methods ?
  • What are Events ?
  • How to avoid confusion?
  • How to reference objects ?


In FoxPro/Windows we had private and public variables. In Visual FoxPro there are some more type of variables. Additionaly all types of controls have properties - think of them as variables bound to a control. Some examples:

       commandbutton.caption     = text shown on the button

       textbox.comment                  = a note of the developer

Even better might be this description: Public vars with a private path as you can access properties from everywhere as long as you know where they live.

You can add your own properties to a control! Later on you will need them. You can use them for non-visual objects or even applications-objects.

What are METHODS?

Methods are procedures. Think of them as old-style snippets, saved in a memo-field and compiled when you close the memo. They are proceduress bound to Controls/Forms instead staying in an individual program (or generated screen-file).

Some Examples:

       Refresh                  Repaint the object

       SetFocus               Make object the current object

Even better might be this description: Public functions with a private path as you can access methods from everywhere as long as you know where they live. Might remind you to the construct DO <function> IN.

You can add your own methods as you can add properties. You will sometimes need your own methods. Building your own is real fun as you can really encapsulate code with the object and e.g. build protected invisible internal methods that can only seen and used be the object itself.

What are EVEN3TS?

Events occur outside of program control and the application has to react to them - at least if it is an event-driven application. In connection with controls, events are bound to methods. Therefore you can think of them as old-style snippets called when something happened. They are procedures bound to Windows-Events.

Some Examples:

       VALID                   old-fashioned VALID-event

       CLICK                    a mouse-click happened on a control

You can not extend the available set of events. Think of events as a fixed set of methods that are bound to the operating system events, internal events of Visual FoxPro (like a Timer event) or an action of the user (like a mouse-click or mouse-move).

You normally need only some of them - but it is great that there are so many! In most controls nearly all events are left blank except for e.g. the click-event.

Avoid Confusion

As there are a lot of properties, methods and events you can easily get confused. Do not do that <g>. Just remember that both, Events and Methods, have a Procedure that can be called. In case of methods it is only called by your code, in case of events these procedures can be called from someone else additionaly. By the way: Therefore sometimes code that should be placed in an event is put into a separate method and called from the event instead, to ease access.

Events could also be seen as an regular Event that occured and a Method bound to that event. On the other hand some properties are followed by actions (and can be seen as events too).

These Categories are not closed boxes, do not loose to much time to distinguish events and methods. There are many - but most are easy to use! Do not get confused by the sheer mass of things you see in the property sheet.

When dealing with the property sheet and all these properties, events and methods you should obey  the graphical hints Visual FoxPro provides.

·         Bold = changed

·         Italic = read-only

If you switch a property and aftterwards switch it back to ist default value it is still marked in bold. Use RESET TO DEFAULT (located on the menu of the right mouse button) to get rid of unwanted changes. This sets back the original graphical hints.


As mentionend above you can access all properties of all controls by a special access path. The syntax definition for accessing them:

                       objectvariable.[form.] = Setting

As the hierarchy of controls can end up with a very long list, there are some shurtcuts implemented:

THIS.                                              the actual control

THISFORM.                                  the actual form

THISFORMSET.                          the actual formset

_SCREEN.                                     the FoxPro main window

ACTIVEFORM.                            the active form of  a form set

ACTIVEPAGE.                             the active page of a page frame

ACTIVECONTROL.                     the active control on a container

PARENT.                                       the parent object (not inheritance!)

The THIS-shortcuts can only be used within methods.

The ACTIVE-shortcuts are connected to a logical property of the control - you can cycle through this property in all associated controls to find inactive ones.

The keyword PARENT. should be fully understood. It has got nothing to do with the inheritance or the parent class (see below). It is just the object in which the control resides. In case of a option button the parent is the optino button group. If a command button is placed on a form the form is the parent, if it is placed in a command button group the group is the parent. This keyword is extremly usefull if you build a group of controls that belong together. If you reference the connected objects via PARENT. you never need to know  who the parent (Allis?) is.

To short writing of references you can use the construct WITH.. ..ENDWITH for a group of properties to be used with the same reference.

If you do not know  the childs of a container object, there are clauses like COUNT or PAGES that behave like arrays of the child objects and can be used to reference all of them or a special one by adding a number in a bracket.

Controls - A Guided Tour

Here is the list of controls we will  visit in this order:

  • Timers
  • Lines
  • Shapes
  • Images
  • Labels
  • Command Buttons
  • Option Buttons
  • Check Boxes
  • Text Boxes
  • Edit Boxes
  • Spinners
  • Option Groups and Command Groups
  • Combo Boxes
  • List Boxes
  • Page Frames
  • Pages
  • OLE-Controls

Not all of them are new! Most of them are renamed. Here is the list of renamed controls:

Text                                =>           Label control

GET-Field                      =>           Text box

Edit Region                   =>           Edit box

Popup                            =>           Combo box

Radio button                 =>           Option button

Screen                            =>           Form

ScreenSet                      =>           FormSet

Picture                            =>           Image

Really new are:

Timers                            =>           for timed events (at least a small help)

Pages/Pageframe          =>           for these nice tabbed dialogs

Grid                 =>           the all-new-version of the browse-command

Basic Example

Lets start with a new but small one: Timers

Data                                Comment, Tag

Methods                        BASIC, TimerEvent, Reset

Layout                           COORDINATES

Other                              CLASS, Interval

Tips                                Not executed while Menu open

                                        Not exact enough for RealTime

special Timer Property/Event/Method

IntervalProp.                 Timer in milliseconds

TimerEvent                    Procedure called at Event

ResetMethod                                Restart timer

Basic Data

Comment                       You should use it!

Tag                                 Free property

Basic Layout

Top                                 ...

Left                                 ...

Heigth                            ...

Width                             ...

Basic Other

Name                              Naming conventions

Enabled                          logical Flag

Class                              Objects belong to classes

ClassLibrary                  optional: VCX of the class

Baseclass                      Base class derived from

Parentclass                    optional: derived from

Parent                             runtime: container object

Basic Events

Init                                  Object initialised

Destroy                          Object removed

Error                               local error-handler

Basic Methods

CloneObject                  runtime duplication

SaveAsClass                                objects from VCX to VCX

ReadExpression            Method at design time

WriteExpression           Method at design time

Visible Objects


Data                                ---

Events                            CLICK, MOUSE, DRAG

Methods                        Drag, Move, UIEnable, ZOrder

Layout                           DragIcon/Mode, BORDER,

                                        Draw- Mode, MousePointer, LineSlant

Other                              HelpContextID

Tips                                No 3D-line-effects

Click Events for visible Objects

Click               Mouse left click

DblClick         Mouse double click

RightClick      Mouse right click

Mouse Events for visible Objects

MouseMove Mouse over object

MouseDown Mouse pressed for click

MouseUp      Mouse released

MousePointer               12 pointer versions

Drag & Drop for visible Objects


DragDrop                      End of drag, target event

DragOver                       object over target, target event


Drag                               Method for manual dragging

Move                             Method for manual moving


DragIcon                       Cursor Icon for drag

DragMode                     automatic / manual

Properties for Visible Objects




Visible                                            Temporary hide object

HelpContextID                              for HelpCompiler

ZOrder Meth.                                active Page, tlb order

UIEnable Evt.                                Page activate event

Drawmode                                     16 different modes


LineSlant                                      special line property

Plain Objects


Data                                ---

Methods                        ---

Layout                           BackColor/Style, FillColor/Style

                                        ColorScheme/Source, ToolTip; SpecialEffect, Curvature

Other                              ---

Tips                Shapes in front block the click event

Properties for Plain Objects


BackStyle                      Transparent / Opaque (Default)

BackColor                      RGB-Color for Qpaque objects

FillColorStyle                Transparent, Solid, Lines

FillColor                         RGB-Color if not transparent

ColorScheme Object/Form/Source/Default

ColorSource                  Scheme for Above=Source

ToolTipText                  ToolTip if Form.ShowTips=.T.

SpecialEffect                 Plain or 3D

Curvature                     0=rectangle - 99=circle


Data                                ---

Methods                        ---

Layout                           Picture  (Bitmap, Icon)

                                        Stretch (Clip/Isometric/Stretch)

Other                              ---

Tips                                Stretch also used for OLE

Objects with Caption


Data                                ---

Methods                        ---

Layout                           Caption, FONT, COLOR,

                                        AutoSize, WordWrap, Alignment

Other                              --

Tips                                The Caption can be a function

Layout Properties for Objects with Caption

FontName                      Fontname

FontSize                         Fontsize

FontFlags                      FontBold, FontItalic, FontStrikeThru,

                                        FontOutline, FontUnderline, FontShadow

DisabledBackColor      Color

DisabledForeColor       Color

ForeColor                      Color

Caption                          Text to be shown (function)

Alignment                     Left/Right/Centered

AutoSize                        Resize horiz. for text

WordWrap                    Wrap words/resize vertical

Accessible Objects

Command Buttons

Data                                TerminateRead

Methods                        ErrorMessage, see EVENTS

Layout                           DownPicture, DisabledPicture

                                        StatusBarText, (Style=Inv.)

Other                              TabIndex, TabStop (Forms!)

                                        Default, Cancel

Tips                                Use small fonts with pictures Use StatusBarText instead

Events for accessible objects

When                             old-fashioned WHEN

Valid                               old-fashioned VALID

GotFocus                       Tabbed to it

LostFocus                     Tabbed somewhere else...

SetFocus                       Method (enabled & visible)

KeyPress                       Key Preview Event

Refresh                          SHOW GET (Requery,Page)

Message                        Return Message text (Old!)

Option Buttons

Data                                ControlSource                      Field or memvar

                                        Value                                      same type as ControlSource

Methods                        ---

Layout                           Alignment (Left/Right) for button

                                        SpecialEffect not for command button

Other                              ---

Tips                                Only in Option Button Groups!

Avoid Confusion

Name                              object name

Caption                          title

ControlSource              differs




Value                              object value

Check Boxes

Data                                ---

Methods                        InteractiveChangeEvent P rogrammaticChangeEvent

Layout                           ---

Other                              ---

Tips                                ProgrammaticChange important!

Objects with entered data

Text Boxes

Data                                Format, InputMask, Margin, Read-Only, Open/MemoWindow

Methods                        RangeHigh, RangeLow

Layout                           SELECT, Style (SAY-compatible), PasswordChar

Other                              HideSelection

Tips                                - Play with selected areas!

Selected Text

SelStart                          Begin of selection

SelLength                      Number of chars

SelText                           Complete Selected text

HideSelection               Show after LostFocus

SelectedForeColor       Text color

SelectedBackColor       Background color

Edit Boxes

Data                                MaxLength

Methods                        ---

Layout                           ScrollBars (vert. & horiz.)

Other                              AllowTabs

Tips                                - „Selected text“ applies here


Data                                KeyboardHigh/LowValue, SpinnerHigh/LowValue, Increment

Methods                        UpEvent, DownEvent

Layout                           ---

Other                              ---

Tips                                                - Use High/LowValues instead of RangeEvents

Combo and List boxes

Combo Boxes

Data                                                BoundColumn, DisplayValue

Methods                                        AddItem, AddListItem,

Layout                                           ColumnCount, -Lines, -Width,


Other                                              TopIndex, TopItemID, +NEW

                                                        IncrementalSearch, Listcount,ListIndex, ListIdemID

Layout for Combo box

ColumnCount                               Number of Columns

ColumnLines                 Show column lines

ColumnWidth                               Width of columns (colon-delimited)







Data for Combo box

RowSourceType                          9 options

RowSource                                    name type

BoundColumn                              Column bound to Value

DisplayValue                                Text or pos. for display

ItemData                                        Additional value

List                                                 Array of text

Sorted                                            Alphabetically sorted

FirstElement                                  for Arrays only

NumberOfElements                      for Arrays only

Methods for Combo box

Requery                                         Requery SQL/QPR-Source

Other for Combo box

IncrementalSearch                       self-explanatory

TopIndex                                       first visible item

NewIndex                                      last AddItem-position

Listcount                                       Number of items

ListIndex                                       (Last) selected item

What are Ids?

ItemIDData                                    Additional value by ID

ListItem                                          Array of text by ID


TopItemID                     ID of topmost vis. list-item

NewItemID                    last AddItem-ID

ListItemID                     (Last) selected item ID 

Do not get confused by the pairs List / ListItem and ListIndex / ListItemID!

The RowSourceType (0=None), (1=Value)

ID-Methods in a Combo box

AddItem                                        Add at position

AddListItem                                  Add with ID

RemoveItem                                  Remove from position

RemoveListItem                           Remove with ID

Clear                                               Delete all items

IndexToItemID                             Position -> ID

ItemIDToIndex                             ID -> Position

List Boxes

Data                                                ---

Methods                                        ---

Layout                                           ---

Other                                              MultiSelect

Tips                                                Use DisplayValue and Value together for text and offset


Container hierarchy

FormSet                                         Form

Form                                               Pageframe, Grid, Controls

PageFrame                                     Pages

Page                                               Grid, Controls

Grid                                 Columns

Column                                          Header, Controls

Option Group                                Option Buttons

Command Group                          Command Buttons

Option/Command Button Groups

Data                                                ---

Methods                                        AddObject, RemoveObject

Layout                                           ButtonCount

Other                                              Buttons 

Tips                                                ChangeEvents only in Groups

                                                        No Inheritance for new buttons

Page Frames

Data                                                ActivePage

Methods                                        ---

Layout                                           PageCount, PageHeight/Width,Tabs, TabStretch

Other                                              Pages (Array)

 Tips                                               Drop objects on top for all pages


Data                                                Controls (Array)

Methods                                        ---

Layout                                           ControlCount

Other                                              PageOrder, KeyPreview

Tips                                                - Reference all with PAGES


As Grids are the most complex controls you can have, an own session is donated to them. Most important for you to know is, that a Grid is a container that can consist of Headers and Columns. Columns are containers too as they consist of e.g. text objects or other types of controls. It is really complicated to build a Grid by hand or programmatically. You should start building grids on your own with the help of the Grid Builder - otherwise it will be real pain. The best might be to have a look at the Session „Using the Grid Control“ from Whil Hentzen.


There are two type of OLE-controls. First you have OLE Bound Controls which are "bound" to Genearl-fields and have no own Events. Second you have OLE Container Controls which are an OCX with own Events connected to it or an other OLE not bound to fields. The OCX-libraries are new to the FoxPro world and give us the power VisualBasic-users had with the old-fashioned VBX-libraries. Have a look at the Session „OLE Custom Controls“ from Steven Black, who will introduce you a lot of never-seen (at least in the FoxPro world) controls you can buy at the fast growing Third-Party-market.


To avoid container-confusion, you need to distinguish three types of controls, that might contain other controls.

  • Container Objects                                  The official visual container control type:

                                                                                       FrameSet, Frame, PageFrame, Page, Grid,

                                                                                       Column, Option Group, Command Group

  • Control Objects                                      A container with protected objects in it
  • Custom Objects                                     A non-visual-class that might contain other objects

Some tips and hints

Ease your work with Naming Conventions

If you have not worked with naming conventions, switching to Visual FoxPro is a good point to start with it. To minimize confusion with all these new types of controls, naming conventions are a must.

chk   Check box

cbo   Combo box

cmd  Command

cmg  Com. group

cnt    Container

ctl     Control

(cus  Custom)

edt    Edit box

frm   Form

frs     Form set

grd    Grid

grc    Grid column

grh    Grid header

img    Image

lbl      Label

lin      Line

lst       List box

olb     OLE-bound

ole     OLE

opt      Option button

opg    Option group

(otl     Outline)

pag     Page

pgf     Page Frame

sep     Separator

shp     Shape

spn     Spinner

txt      Text box

tmr     Timer

tbr      Toolbar

Ease your work with Builders

You should really ease your work with the new Builders. We have gone the hard way today doing everything manual - but with the builders you are ten times faster for everydays work. There are builders for these controls:

  • Text box
  • Edit box
  • List box
  • Combo-Box
  • Option Group
  • Command Group
  • Grid

By the way, Builders use these special design methods every control has build in:

  • ReadMethod
  • WriteMethod
  • ReadExpression
  • WriteExpression

And the function „ASelObj( )“ will help you to find the selected objects in case you build a builder on your own. Take a look at a builder-session to find out  more about these predecessors of GenScrnX. You will love them!

Where to go from here?

There is a lot more to learn about Visual FoxPro and ist new user interface. Try one of the following sessions here on FoxTeach:

  • The Form Designer - Alan Schwartz
  • Advanced Visual FoxPro Controls - Ted Roche
  • Using the Grid Control in the Real World - Whil Hentzen
  • OLE Custom Controls in Visual FoxPro - Steven Black
  • Builders in Visual FoxPro - Steven Black
  • Using Visual FoxPro Classes - Ken Levy
  • The Class Browser - Ken Levy

I know all of these speakers and really recommend their sessions to you.

About the speaker:

Rainer Becker has been programming with Foxpro for several years. He is the founder of the German FoxPro User Group dFPUG, a semi-professional group of 1100+ programmers in Germany, Austria and Switzerland. The dFPUG publishes a bimonthly 32-pages newsletter with companion disk, it organizes 120 small meetings, 50 workshops and a FoxPro developers conference a year and provides an own section in CompuServe. His main profession is programming complete software packages for public school administrations, corporate controlling departments and publishing companies. You can reach him via Fax (01149-6173-65997), Phone (01149-6173-68182) and CompuServe (CIS-ID 100024,1364) or by placing a message in the dFPUG-section (GO MSCESYS).