KeyPress example for Visual Basic

This example demonstrates the KeyPress event.

Private Sub Lead1_KeyPress(KeyAscii As Integer)

    'This example uses the KeyPress event to implement a custom scale mode.
    'There is no particular reason to put this code in this event, except that
    'we needed examples of both the event and the scale mode.

    If KeyAscii = 67 Then 'Uppercase C
        'This example sets an custom scale mode and uses it to crop the
        'display. Keep in mind that the actual height and width do not change.
        'Only the unit of measure changes.

        'Change the scale so that origin is moved one-third right and one-third down
        Lead1.ScaleLeft = -1
        Lead1.ScaleTop = -1
        Lead1.ScaleWidth = 3
        Lead1.ScaleHeight = 3

        'Crop the display so that it takes up the middle third of the height and width
        Lead1.DstClipLeft = 0
        Lead1.DstClipTop = 0
        Lead1.DstClipWidth = 1
        Lead1.DstClipHeight = 1

        Lead1.ForceRepaint
    End If

End Sub