• No results found

5.3 Building the user interface

5.3.9 AlphaPad

© Copyri ght 200 7 - 2009 ABB . All ri ghts res erved.

5.3.9. AlphaPad

Overview

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

6.2.10_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 by the figure in the

next section. Code is of course generated for it, just like for controls that are visually laid out on the form in design-time.

5.3.9. AlphaPad © Copyri ght 200 7 - 2009 ABB . All ri ghts res erved.

Launching the AlphaPad

You need to write some code to launch the virtual keyboard. This is how you do it: C#:

this.alphaPad1.ShowMe(this);

VB:

Me.AlphaPad1.ShowMe(Me)

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:

if (alphaPad1.SelectedText != string.Empty) {

_userInput = alphaPad1.SelectedText; }

6.2.10_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:

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

Continued

5.3.9. AlphaPad © Copyri ght 200 7 - 2009 ABB . All ri ghts res erved. End If End Sub 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; } }

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:

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

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(); } Continued

5.3.9. AlphaPad © Copyri ght 200 7 - 2009 ABB . All ri ghts res erved.

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 example above, 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!

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 on page 93.

5.3.10. ListView © Copyri ght 200 7 - 2009 ABB . All ri ghts res erved.

5.3.10. ListView

Overview

The ABB.Robotics.Tps.Windows.Forms.ListView is very similar to a standard .Net

ListView. The main difference is that its appearance is somewhat adapted to the use of a touch screen, as can be seen in the figure.

You can use the ListView control in a variety of ways. Usually you use it to display a list of items with item text and, optionally, an icon to identify the type of item. By using the

CheckBoxes property it is also possible to have a check box appear next to each item in the

control, allowing users to check the items they want to perform an action on. Illustration

The figure shows the Designer. You see two different ABB ListView lists, a standard .Net

ImageList in the components pane under the lists and the Properties window for the Calibration, HotEdit list.

6.3.10_1

Using properties to control appearance

The first list has CheckBoxes set to true. To have columns displayed View must be set to

Details. The columns are created by selecting Columns and adding any number of columns

in the ColumnHeader Collection Editor. Scrollable has been set to true to enable the user to scroll the list to see all items. To have the current number of list items displayed