Home > Language Reference > Classes
UserControl Class
+ Object
+ Display
+ UIComponent
+ Control
+ UserControl
Description
The UserControl class implements functionalities common to all user controls. This class is not instantiable, cloneable or directly derivable. To create a user control, you should create a new module in your project by selecting the "Project > Add user control" menu then review its different design time properties. The module thus created declares a new class whose name is given by the Name property and the parent class is UserControl.
You can then place as many instances of this new control wherever you want on forms, just like you can do with any other built-in control, by selecting the corresponding control icon in the Toolbox Window of the development environment.
By default, a user control has no defined behaviour and aspect: it does not appear on screen and does not respond to taps by the user. So that your control behaves correctly, you should implement event handlers for the different events that can occur.
The principal event is Paint which is raised by the system whenever the control needs to be redrawn. Except in special cases, all control drawing procedures must be located in this event handler otherwise your control may not appear properly on screen.
Inherited from the UIComponent class, the PenDown, PenMove and PenUp events are raised respectively when the user presses down, moves and release the stylus on the control.
Finally, the Load and Unload events are raised when loading and unloading the form that contains the control, and can be used to initialize the values of member variables, and load or free up resources.
The following example shows how to create a user control that displays the available memory space in the heap, either as a gauge or a number. The user can switch from one display mode to the other by tapping the control.
Private bText As Boolean
Private lMemSize As Long
Private lMemFree As Long
Private Sub UserControl_Load()
bText=False
lMemSize=MemInfo(hbMemHeapSize)
lMemFree=MemInfo(hbMemHeapFree)
End Sub
Private Sub UserControl_Paint()
Dim k as Long, s as String
If bText Then
ForeColor=UIColor(hbUIObjectFrame)
BackColor=UIColor(hbUIObjectFill)
Rectangle 0, 0, Width-1, Height-1, hbRectBorderSolid+hbRectFillSolid
DrawFont = hbFontStandard
TextColor=UIColor(hbUIObjectForeground)
s = Format(lMemFree/1024.0,"#.00") & " Ko / " & Format(lMemSize/1024.0,"#.00") & " Ko"
Textout Width/2, Height/2,s,hbTextAlignCenter+hbTextAlignVCenter
Else
ForeColor=UIColor(hbUIObjectFrame)
BackColor=UIColor(hbUIObjectFill)
Rectangle 0, 0, Width-1, Height-1, hbRectBorderSolid+hbRectFillSolid
k = (Width-3)*(lMemSize-lMemFree)/lMemSize
If k<>0 Then
BackColor=UIColor(hbUIObjectSelectedFill)
Rectangle 1, 1, k+1, Height-2, hbRectBorderNone+hbRectFillSolid
End If
End If
End Sub
Private Sub UserControl_PenUp(ByVal x As Integer, ByVal y As Integer)
bText=Not bText
Repaint
End Sub
Members
| Members | Description |
| Load | Event raised when the control is loaded. |
| Paint | Event raised when the control needs to be redrawn. |
| Repaint | Repaints the control. |
| Resize | Event raised when the control is resized. |
| Unload | Event raised when the control is unloaded. |
| Inherited from Control | Description |
| DrawFocusRing | Draws the focus ring. |
| GotFocus | Event raised when the control gains the focus. |
| Layer | Layer to which the control belongs. |
| LostFocus | Event raised when the control loses the focus. |
| NavFlags | Navigation flags for the control. |
| RemoveFocusRing | Erase the focus ring. |
| Tag | String associated with the control. |
| Visible | Indicates if a control is visible or not. |
| Inherited from UIComponent | Description |
| ComponentToScreen | Converts coordinates relative to a component into coordinates relative to the screen. |
| FiveWayNavigator | Event raised when the user presses one of the 5-way navigator keys. |
| Height | Element height. |
| Left | Distance between the left edge of the form and the left edge of the element. |
| Move | Moves or resizes an element. |
| PenDown | Event raised when the user touches an UI element with the stylus. |
| PenMove | Event raised when the user moves the stylus. |
| PenUp | Event raised when the user releases the stylus. |
| ScreenToComponent | Converts coordinates relative to the screen into coordinates relative a component. |
| Top | Distance between the top edge of the form and the top edge of the element. |
| UIRef | Internal reference to a control. |
| Width | Element width. |
| Inherited from Display | Description |
| Arc | Draws an arc. |
| BackColor | Background color. |
| BatchLimit | Size of the graphics instruction buffer. |
| CoordinateSystem | Coordinates system. |
| CopyArea | Efficiently copies part of a Display object to another. |
| DrawFont | Font used to draw the text. |
| Flush | Empties the graphics instruction buffer. |
| FontMetrics | Returns a FontMetrics object describing the physical charateristics of the currently active font. |
| ForeColor | Foreground color. |
| GetPixel | Queries the color of a given pixel. |
| hWin | Returns the window handle. |
| Line | Draws a line. |
| Oval | Draws a circle or ellipse. |
| Pattern | Defines the pattern used to fill drawings. |
| Polygon | Draws a polygon. |
| PutPixel | Sets the color of a pixel. |
| Rectangle | Draw a rectangle. |
| ResID | Identifier of the resource associated with the object. |
| ScaleFont | Enable or disable font scaling. |
| TextColor | Text color. |
| TextOut | Draw text. |
| Inherited from Object | Description |
| ClassID | Returns the type identifier corresponding to the actual class of the object. |
| Implements | Determines whether the object implements the features of a given class. |
| Iterate | Event raised to iterate over the elements of a container object. |
| Recipient | Recipient of events sent by the object. |
| Serialize | Event raised to serialize the object content into a stream. |
System requirements
| System | Minimal version | Remarks |
| Palm OS | Palm OS 3.0 | N/A |