Click or drag to resize

AlphaPad

Overview

The AlphaPad control is a virtual keyboard, which enables you to enter strings. It covers the whole FlexPendant display. The figure shows its appearance in run time.

alphapad 1

The AlphaPad has no graphical representation in design-time. When dragged from the Toolbox to the Designer it is placed in the components pane, as shown in the figure in the next section. Code is generated for it similar to controls that are visually laid out on the form in design-time.

Launching the AlphaPad

You need to write some code to launch the virtual keyboard. The following code explains how you do it:

C#
this.alphaPad1.ShowMe(this);

VB
Me.AlphaPad1.ShowMe(Me)

Note Note

The code for launching the AlphaPad should be executed by an appropriate event handler.

Adding event handlers

The Properties window can be used to program AlphaPad event handlers. You double-click the event you want to respond to. This takes you to the code editor, the cursor placed inside the auto generated event handler, where you can write code to save user input to a member variable for example:

C#
if (alphaPad1.SelectedText != string.Empty)
{
_userInput = alphaPad1.SelectedText;
}

alphapad 2

Validating the result at the Closing event

The Closing event is generated when the OK or Cancel button of the AlphaPad is pressed. You can use this event to validate the string entered by the user. You can set the Cancel property of the event argument to true if you want the AlphaPad to remain open until a valid input value has been entered:

C#
 private void namePad_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
 if ((this.namePad.SelectedText.CompareTo("No Name") == 0) & (this.namePad.DialogResult == System.Windows.Forms.DialogResult.OK))
 {
 e.Cancel = true;
 }
 }
VB
Private Sub NamePad_Closing(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles NamePad.Closing
If NamePad.SelectedText.CompareTo("No Name") = 0 & NamePad.DialogResult = System.Windows.Forms.DialogResult.OK Then
e.Cancel = True
End If
End Sub
Using the result at the Closed event

The Closed event has to be caught by an event handler, as the object cannot be disposed of until it has been closed. The result may be retrieved in this event handler or in the Closing event handler. First check that OK and not Cancel was pressed, then retrieve user input. Finally the AlphaPad should be disposed of .VB.

C#
private void namePad_Closed(object sender, EventArgs e)
{
if (this.namePad.DialogResult == System.Windows.Forms.DialogResult.OK)
{
this.answer = this.namePad.SelectedText;
}
this.alphaPad1.Dispose();
}
VB
Private Sub NamePad_Closed(sender As Object, e As EventArgs) Handles NamePad.Closed
If NamePad.DialogResult = Windows.Forms.DialogResult.OK Then
Me.answer = NamePad.SelectedText
End IfNamePad.Dispose()
End Sub
Removing the AlphaPad control

The AlphaPad is NOT added to the control collection, and will therefore NOT be disposed of by the base class of its container.

You are responsible for explicitly calling its Dispose method when it is no longer used. In the preceding example, this is done at the Closed event. This implies that a new AlphaPad instance is created the next time its launch event is triggered.

Another way of dealing with this is to let the instance created by the Designer live until its container view is closed. This alternative means destroying it in the Dispose method of the container class:

this.alphaPad1.Dispose();

Caution note Caution

If you forget to call Dispose on an AlphaPad control you will have a memory leak. For further information see GUI controls and memory management.