Available in the LEADTOOLS Imaging toolkit. |
SetRgn... example for Access 2.0
This example demonstrates the SetRgnEllipse, SetRgnRect, SetRgnRoundRect, and SetRgnPolygon methods by simulating client area coordinates. Normally, you would get the coordinates interactively from mouse events and would use Windows GDI functions to outline the shape of each region before it is created.
To create the polygonal region, this example uses the PolygonSize, PolygonX, and PolygonY properties.
Also, to demonstrate the SetRgnColor method, it uses the Fill method to fill the region with a solid color, then uses the fill color to create a new region.
'Declare local variables.
Dim ZoomFactorX As Single 'Used for translating positioning information
Dim ZoomFactorY As Single 'Used for translating positioning information
Dim OffsetX, OffsetY, CurrentX, CurrentY 'To simulate mouse coordinates
Dim SimLeft, SimTop, SimWidth, SimHeight 'To simulate mouse coordinates
Dim LBRgnLeft, LBRgnTop, LBRgnWidth, LBRgnHeight, eW, eH 'For bitmap coordinates
Dim i As Integer 'Loop counter
Static xPoint(0 To 7) As Integer 'Array for polygon points
Static yPoint(0 To 7) As Integer 'Array for polygon points
'Initialize the variables that we will manipulate to simulate mouse coordinates.
OffsetX = Me![LEAD1].Object.ScaleWidth / 15
OffsetY = Me![LEAD1].Object.ScaleHeight / 15
CurrentX = OffsetX
CurrentY = OffsetY
'Set the zoom factors.
ZoomFactorX = Me![LEAD1].Object.DstWidth / Me![LEAD1].Object.SrcWidth
ZoomFactorY = Me![LEAD1].Object.DstHeight / Me![LEAD1].Object.SrcHeight
'Start by simulating the drawing of a rectangle.
SimLeft = CurrentX
SimTop = CurrentY
SimWidth = OffsetX * 2
SimHeight = OffsetY * 2
'Translate the simulated client coordinates to bitmap coordinates.
LBRgnLeft = (SimLeft / ZoomFactorX) - (Me![LEAD1].Object.DstLeft / ZoomFactorX) + Me![LEAD1].Object.SrcLeft
LBRgnTop = (SimTop / ZoomFactorY) - (Me![LEAD1].Object.DstTop / ZoomFactorY) + Me![LEAD1].Object.SrcTop
LBRgnWidth = SimWidth / ZoomFactorX
LBRgnHeight = SimHeight / ZoomFactorY
'Create the rectangular region, outline it, and display a message so that we can see what happened.
Me![LEAD1].Object.SetRgnRect LBRgnLeft, LBRgnTop, LBRgnWidth, LBRgnHeight, L_RGN_SET
Me![LEAD1].Object.RgnFrameType = RGNFRAME_STATIC
MsgBox "Here is the rectangular region"
'Move the current mouse position so that we overlap the existing region.
CurrentX = CurrentX + OffsetX
CurrentY = CurrentY + OffsetY
'Next, simulate the drawing of an ellipse.
SimLeft = CurrentX
SimTop = CurrentY
SimWidth = OffsetX * 3
SimHeight = OffsetY * 2
'Translate the simulated client coordinates to bitmap coordinates.
LBRgnLeft = (SimLeft / ZoomFactorX) - (Me![LEAD1].Object.DstLeft / ZoomFactorX) + Me![LEAD1].Object.SrcLeft
LBRgnTop = (SimTop / ZoomFactorY) - (Me![LEAD1].Object.DstTop / ZoomFactorY) + Me![LEAD1].Object.SrcTop
LBRgnWidth = SimWidth / ZoomFactorX
LBRgnHeight = SimHeight / ZoomFactorY
'Add the elliptical region, using a Boolean OR,
'and display a message so that we can see what happened.
Me![LEAD1].Object.SetRgnEllipse LBRgnLeft, LBRgnTop, LBRgnWidth, LBRgnHeight, L_RGN_OR
Me![LEAD1].Object.RgnFrameType = RGNFRAME_STATIC
MsgBox "Here is the added ellipse, with a Boolean OR"
'Move the current mouse position so that we overlap the existing region.
CurrentX = CurrentX + OffsetX
CurrentY = CurrentY + OffsetY
'Next, simulate the drawing of a rounded rectangle.
SimLeft = CurrentX
SimTop = CurrentY
SimWidth = OffsetX * 3
SimHeight = OffsetY * 2
'Translate the simulated client coordinates to bitmap coordinates.
LBRgnLeft = (SimLeft / ZoomFactorX) - (Me![LEAD1].Object.DstLeft / ZoomFactorX) + Me![LEAD1].Object.SrcLeft
LBRgnTop = (SimTop / ZoomFactorY) - (Me![LEAD1].Object.DstTop / ZoomFactorY) + Me![LEAD1].Object.SrcTop
LBRgnWidth = SimWidth / ZoomFactorX
LBRgnHeight = SimHeight / ZoomFactorY
'Define an ellipse to use for the corners.
eW = LBRgnWidth / 4
eH = LBRgnHeight / 4
'Add the rounded rectangular region, using a Boolean exclusive OR,
'and display a message so that we can see what happened.
Me![LEAD1].Object.SetRgnRoundRect LBRgnLeft, LBRgnTop, LBRgnWidth, LBRgnHeight, eW, eH, L_RGN_XOR
MsgBox "Here is the rounded rectangle, with a Boolean XOR"
'Move the current mouse position so that we overlap the existing region.
CurrentX = CurrentX + (2 * OffsetX)
CurrentY = CurrentY + (2 * OffsetY)
'Set up some arrays to use as client area grid values.
'OffsetX and OffsetY set the grid sizes.
xPoint(0) = 0
xPoint(1) = -1
xPoint(2) = 2
xPoint(3) = 1
xPoint(4) = 1
xPoint(5) = 2
xPoint(6) = -1
xPoint(7) = -2
yPoint(0) = 0
yPoint(1) = -1
yPoint(2) = -1
yPoint(3) = 1
yPoint(4) = -1
yPoint(5) = 1
yPoint(6) = 1
yPoint(7) = 1
'Initialize the polygon size using an arbitrary number.
'This number will be increased dynamically.
Me![LEAD1].Object.PolygonSize = 5
'Fill in the array for the polygon. This simulates a user's mouse clicks.
For i = 0 To 7
CurrentX = CurrentX + (xPoint(i) * OffsetX)
CurrentY = CurrentY + (yPoint(i) * OffsetY)
Me![LEAD1].Object.PolygonX(i) = (CurrentX / ZoomFactorX) - (Me![LEAD1].Object.DstLeft / ZoomFactorX) + Me![LEAD1].Object.SrcLeft
Me![LEAD1].Object.PolygonY(i) = (CurrentY / ZoomFactorY) - (Me![LEAD1].Object.DstTop / ZoomFactorY) + Me![LEAD1].Object.SrcTop
If i + 1 = Me![LEAD1].Object.PolygonSize Then
Me![LEAD1].Object.PolygonSize = Me![LEAD1].Object.PolygonSize + 5
End If
Next
'Adjust the polygon size to the actual number of points.
Me![LEAD1].Object.PolygonSize = i
'Add the polygonal region, using a Boolean OR,
'and display a message so that we can see what happened.
Me![LEAD1].Object.SetRgnPolygon L_POLY_WINDING, L_RGN_OR
MsgBox "Here is the added polygon, with a Boolean OR"
'Fill the resulting polygon with red, and display a message.
Me![LEAD1].Object.Fill RGB(255, 0, 0)
Me![LEAD1].Object.RgnFrameType = RGNFRAME_NONE
Me![LEAD1].Object.ForceRepaint
MsgBox "Using SetRgnColor and L_RGN_SETNOT, all else will become blue."
'Clean up memory
Me![LEAD1].Object.FreeRgn
'Do the final region.
Me![LEAD1].Object.SetRgnColor RGB(255, 0, 0), L_RGN_SETNOT
Me![LEAD1].Object.Fill RGB(0, 0, 255)
Me![LEAD1].Object.ForceRepaint
'Clean up memory
Me![LEAD1].Object.FreeRgn
Me![LEAD1].Object.PolygonSize = 0