Visual Basic Example
The following example displays a Clip image in a picture box when the user specifies X and Y coordinates and then clicks a form. First create a form with a PictureBox, a PictureClip control, and two TextBox controls. At design time, use the Properties sheet to load a valid bitmap into the PictureClip control.
Private Sub Form_Click ()
Dim SaveMode As Integer
' Save the current ScaleMode for the picture box.
SaveMode = Picture1.ScaleMode
' Get X and Y coordinates of the clipping region.
PicClip1.ClipX = Val(Text1.Text)
PicClip1.ClipY = Val(Text2.Text)
' Set the area of the clipping region (in pixels).
PicClip1.ClipHeight = 100
PicClip1.ClipWidth = 100
' Set the picture box ScaleMode to pixels.
Picture1.ScaleMode = 3
' Set the destination area to fill the picture box.
PicClip1.StretchX = Picture1.ScaleWidth
PicClip1.StretchY = Picture1.ScaleHeight
' Assign the clipped bitmap to the picture box.
Picture1.Picture = PicClip1.Clip
' Reset the ScaleMode of the picture box.
Picture1.ScaleMode = SaveMode
End Sub