AddRectangle Method

NI Vision for Visual Basic

AddRectangle Method

Syntax

CWIMAQRegions.AddRectangle Rectangle

Return Type

CWIMAQRegion

The region object that was added.

Purpose

Adds a rectangle region to the regions collection.

Remarks

This method makes a copy of the input rectangle.

Parameters

Rectangle As CWIMAQRectangle

The rectangle to add.

Example

Private Sub Run_Click()
    Dim RotatedRectangle As New CWIMAQRotatedRectangle
    Dim BoundingRectangle As New CWIMAQRectangle
    
    'Create a rotated rectangle
    RotatedRectangle.Initialize 120, 150, 200, 100, 45
    
    'Add the rotated rectangle to the viewer regions.
    CWIMAQViewer1.Regions.AddRotatedRectangle RotatedRectangle

    If TypeName(RotatedRectangle) = "Nothing" Then
    MsgBox "Number of rotated rectangles exceeded!"
    Else
    MsgBox "You added a rotated rectangle." 
    End If
    
    'Add a second rotated rectangle with a different angle to the viewer regions.
    RotatedRectangle.Angle = 15
    CWIMAQViewer1.Regions.AddRotatedRectangle RotatedRectangle

    If TypeName(RotatedRectangle) = "Nothing" Then
    MsgBox "Number of rotated rectangles exceeded!"
    Else
    MsgBox "You added a rotated rectangle." 
    End If
    
    'Get the bounding rectangle of the viewer regions
    CWIMAQViewer1.Regions.GetBoundingRectangle BoundingRectangle
    
    'Add the bounding rectangle to the viewer regions
    CWIMAQViewer1.Regions.AddRectangle BoundingRectangle
    If TypeName(BoundingRectangle) = "Nothing" Then
    MsgBox "Number of bounding rectangles exceeded!"
    Else
    MsgBox "You added a bounding rectangle." 
    End If
    CWIMAQViewer1.Regions(CWIMAQViewer1.Regions.Count).PenColor = vbYellow

End Sub