Sample ABL-derived .NET user control
- Last Updated: September 17, 2019
- 4 minute read
- OpenEdge
- Version 13.0
- Documentation
SampleUserControl is a
sample ABL-derived user control class based on Progress.Windows.UserControl. Progress.Windows.UserControl inherits
from the .NET System.Windows.Forms.UserControl class
and allows you to define a control container that functions as a
user-defined .NET control (user control). In
an ABL-derived user control, you can contain a set of other ABL-derived
user controls, .NET controls, and control containers that
you might want to function together as a single control for use in
several different applications.
SampleUserControl initializes a user control much like an ABL-derived form might initialize itself (see the previous sample ABL-derived .NET classes, for example, as described in Sample ABL-derived .NET non-modal form). In this case, the user control contains two .NET controls:
- A password
field implemented by an Advanced UI Control (
Infragistics.Win.UltraWinEditors.UltraTextEditor) - A Login button implemented by another Advanced
UI Control (
Infragistics.Win.Misc.UltraButton)
The
sample ABL class, UserControlForm, displays this
control container in a non-modal form, and the sample UserControlFormDriver.p procedure
displays the form, as in the following figure.

In the user control, you can type a masked password string in a text box and you can click the Login button, but there is no other behavior implemented for this control.
Note that
in this example, UserControlForm is the only form
class where SampleUserControl is used. Typically,
you design a single ABL-derived user control for use in multiple forms
or applications. For example, a single login user control might
be used in any number of application modules where a user might
be required to enter security credentials.
This is the initial
section of code for the ABL SampleUserControl class,
where the class private data and public members are defined.
|
The rPasswordEditor and rLoginButton variables
define PRIVATE object references to the control
objects contained by the user control. The read-only PasswordEntry and LoginButton properties
provide PUBLIC object references to these control
objects for use by the form that contains the user control. This
sample does not use these properties except to assign them references
to their associated control objects.
As is
typical for ABL container classes, the constructor invokes an InitializeComponent( ) method,
which instantiates and initializes the user control.
The InitializeComponent( ) method
follows, which completes the SampleUserControl class.
|
The general initialization process is exactly
like initializing a .NET form. It starts by initializing its
two control objects contained by the user control (rPasswordEditor and rLoginButton)
and setting public properties for them. The Location property settings
for each control are relative to the client area of the user control.
When the user control is added to a form, its Location property
is then specified relative to the client area of the form, thus
positioning all constituent controls of the user control on the
form as a unit. The AutoScale* properties
allow the user control and its controls to scale with its form,
according to the system font size.
CAST function
enables access to the explicit interface members, BeginInit( ) and EndInit( ),
which are required to initialize the UltraTextEditor control
(see Access members of .NET interfaces).This is the code for the sample ABL-derived
client form class of SampleUserControl, UserControlForm.
|
With the SampleUserControl class,
form initialization in the ABL UserControlForm class
becomes much simpler than for the previously described ABL-derived
non-modal form classes (for example, CurrentTimeForm described
in Sample ABL-derived .NET non-modal form). In this case, there
is one object reference (demoControl) for all the
controls on the form. Control initialization is a matter of using
this one object reference to position the control container in the
client area of the form by setting its Location property
and to add the control container to the form's control collection. UserControlForm could also
use the other public properties of SampleUserControl to
subscribe event handlers to its control events, if the application
required it.