home *** CD-ROM | disk | FTP | other *** search
- VERSION 5.00
- Object = "{52DE3A21-0A3F-11D4-B9D2-008048FD54E6}#2.0#0"; "POLARD~1.OCX"
- Begin VB.Form Form1
- Appearance = 0 'Flat
- BackColor = &H80000004&
- BorderStyle = 1 'Fixed Single
- Caption = "Polygon vertices Sample"
- ClientHeight = 9450
- ClientLeft = 150
- ClientTop = 720
- ClientWidth = 9315
- LinkTopic = "Form1"
- MaxButton = 0 'False
- ScaleHeight = 9450
- ScaleMode = 0 'User
- ScaleWidth = 9315
- StartUpPosition = 3 'Windows Default
- Begin POLARDRAW20Lib.POLARDraw POLARDraw1
- Height = 9255
- Left = 2640
- TabIndex = 22
- Top = 0
- Width = 6495
- _Version = 131072
- _ExtentX = 11456
- _ExtentY = 16325
- _StockProps = 224
- PaperShadowColor= 1241780
- DrawPaperOutline= -1 'True
- DrawPaperShadow = -1 'True
- PaperShadowOffset= 23780436
- ViewportOriginX = 5813754
- ViewportOriginY = 66487384
- PageOriginX = 2012272201
- PageOriginY = 440
- HorizontalGrid = 567
- VerticalGrid = 567
- SelectionCount = 2011661766
- ShapeCount = 1598273252
- CanvasWidth = 0
- CanvasHeight = 1598275446
- End
- Begin VB.CommandButton bttnConvertToPolygon
- Caption = "Convert To Polygon"
- Height = 375
- Left = 480
- TabIndex = 21
- ToolTipText = "Converts selected shape to polygon."
- Top = 3480
- Width = 1815
- End
- Begin VB.ComboBox cmbShapeType
- Height = 315
- Left = 480
- Style = 2 'Dropdown List
- TabIndex = 19
- ToolTipText = "Specifies type of shape to be drawn."
- Top = 2160
- Width = 1815
- End
- Begin VB.CommandButton btnClearAll
- Caption = "Delete All"
- Height = 375
- Left = 480
- TabIndex = 17
- ToolTipText = "Deletes all polygons."
- Top = 600
- Width = 1815
- End
- Begin VB.CommandButton btnDelete
- Caption = "Delete"
- Height = 375
- Left = 480
- TabIndex = 16
- ToolTipText = "Deletes selected polygons."
- Top = 120
- Width = 1815
- End
- Begin VB.ComboBox cmbEditMode
- Height = 315
- Left = 480
- Style = 2 'Dropdown List
- TabIndex = 2
- ToolTipText = "Specifies one of Edit Modes."
- Top = 1440
- Width = 1815
- End
- Begin VB.ComboBox cmbPolygonType
- Height = 315
- Left = 480
- Style = 2 'Dropdown List
- TabIndex = 1
- ToolTipText = "Specifies type of polygon that will be drawn (use if Curent Shape Type = Freeform)."
- Top = 2880
- Width = 1815
- End
- Begin VB.Frame Frame1
- Caption = "Polygon info:"
- Height = 5175
- Left = 240
- TabIndex = 4
- ToolTipText = "Provides informations about selected polygon."
- Top = 4080
- Width = 2295
- Begin VB.CommandButton btnReCalculate
- Caption = "Recalculate"
- Height = 375
- Left = 240
- TabIndex = 18
- ToolTipText = "Re-calculate vertex positions (use after moving vertex by mouse)"
- Top = 4560
- Width = 1815
- End
- Begin VB.TextBox txtVertYPos
- Height = 285
- Left = 240
- TabIndex = 15
- ToolTipText = "Vertex y position, relative to the bounding box of polygon."
- Top = 4080
- Width = 1815
- End
- Begin VB.TextBox txtVertXPos
- Height = 285
- Left = 240
- TabIndex = 13
- ToolTipText = "Vertex x position, relative to the bounding box of polygon."
- Top = 3480
- Width = 1815
- End
- Begin VB.CommandButton btnMoveMinus
- Caption = "Move vertex -"
- Height = 375
- Left = 240
- TabIndex = 11
- ToolTipText = "Moves vertex, specified by vertex index, up and left for 2000 units relative to bounding box of polygon."
- Top = 2160
- Width = 1815
- End
- Begin VB.CommandButton btnMovePlus
- Caption = "Move vertex +"
- Height = 375
- Left = 240
- TabIndex = 10
- ToolTipText = "Moves vertex, specified by vertex index, down and right for 2000 units relative to bounding box of polygon."
- Top = 2640
- Width = 1815
- End
- Begin VB.TextBox txtVertexIndex
- Height = 285
- Left = 240
- TabIndex = 9
- ToolTipText = "You can select this number and type other number instead. "
- Top = 1680
- Width = 1815
- End
- Begin VB.TextBox txtVertCount
- Height = 285
- Left = 240
- Locked = -1 'True
- TabIndex = 7
- ToolTipText = "To get correct count of vertices, after adding new vertex by mouse in Edit Points Mode, click once again with mouse on polygon."
- Top = 1080
- Width = 1815
- End
- Begin VB.CommandButton btnPolygonInfo
- Caption = "Set Polygon Info"
- Height = 375
- Left = 240
- TabIndex = 6
- ToolTipText = "Sets informations about selected polygon"
- Top = 360
- Width = 1815
- End
- Begin VB.Label Label6
- Caption = "Vertex y position:"
- Height = 255
- Left = 240
- TabIndex = 14
- ToolTipText = "Vertex y position, relative to the bounding box of polygon."
- Top = 3840
- Width = 1215
- End
- Begin VB.Label Label5
- Caption = "Vertex x position:"
- Height = 255
- Left = 240
- TabIndex = 12
- ToolTipText = "Vertex x position, relative to the bounding box of polygon."
- Top = 3240
- Width = 1215
- End
- Begin VB.Label Label4
- Caption = "Vertex index:"
- Height = 255
- Left = 240
- TabIndex = 8
- ToolTipText = "Specifies a vertex of selected polygon."
- Top = 1440
- Width = 1575
- End
- Begin VB.Label Label3
- Caption = "Vertices count:"
- Height = 375
- Left = 240
- TabIndex = 5
- ToolTipText = "Number of vertices in selected polygon."
- Top = 840
- Width = 1335
- End
- End
- Begin VB.Label Label7
- Caption = "Current Shape Type:"
- Height = 255
- Left = 480
- TabIndex = 20
- ToolTipText = "Specifies type of shape to be drawn."
- Top = 1920
- Width = 1575
- End
- Begin VB.Label Label2
- Caption = "Current Edit Mode:"
- Height = 255
- Left = 480
- TabIndex = 3
- ToolTipText = "Specifies one of Edit Modes."
- Top = 1200
- Width = 1695
- End
- Begin VB.Label Label1
- Caption = "Current Polygon Type:"
- Height = 255
- Left = 480
- TabIndex = 0
- ToolTipText = "Specifies type of polygon that will be drawn (use if Curent Shape Type = Freeform)."
- Top = 2640
- Width = 1695
- End
- Begin VB.Menu show
- Caption = "&Show"
- Index = 1
- Begin VB.Menu guidelines
- Caption = "&Guidelines"
- Checked = -1 'True
- Index = 1
- Shortcut = ^G
- End
- Begin VB.Menu connectors
- Caption = "&Connectors"
- Index = 1
- Shortcut = ^N
- End
- Begin VB.Menu grid
- Caption = "&Grid"
- Index = 1
- Shortcut = ^R
- End
- End
- Begin VB.Menu about
- Caption = "&About"
- Index = 1
- Begin VB.Menu sample
- Caption = "&This Sample"
- Index = 1
- End
- Begin VB.Menu draw
- Caption = "&POLAR Draw 2.0"
- Index = 1
- End
- End
- Attribute VB_Name = "Form1"
- Attribute VB_GlobalNameSpace = False
- Attribute VB_Creatable = False
- Attribute VB_PredeclaredId = True
- Attribute VB_Exposed = False
- Dim pd_environment As POLARDRAW20Lib.Environment
- Public arr_PolygonTypeConstants As Variant
- Public arr_PolygonTypeNames As Variant
- Public arr_EditModeConstants As Variant
- Public arr_EditModeNames As Variant
- Public arr_ShapeTypeConstants As Variant
- Public arr_ShapeTypeNames As Variant
- Public IsCalculatedPolygonInfo As Boolean
- Public myShape As POLARDRAW20Lib.Shape
- 'Object myPoly is polygon we set info for.
- Public myPoly As POLARDRAW20Lib.Shape
- 'Object myVertices represents all vertices of myPoly.
- Public myVertices As POLARDRAW20Lib.Vertices
- 'Object myVertex represent one vertex of myPoly.
- Public myVertex As POLARDRAW20Lib.Vertex
- 'ItemIndex is index of myVertex in Vertices collection object.
- Public ItemIndex As Long
- Private Sub btnClearAll_Click()
- 'Deletes all polygons.
- On Error Resume Next
- For Each element In POLARDraw1.ActivePage.Shapes
- If (myPoly Is Nothing) Then
- POLARDraw1.ActivePage.Shapes.Delete
- Else
- If (element.ID = myPoly.ID) Then
- Set myPoly = Nothing
- txtVertCount = ""
- txtVertexIndex = ""
- txtVertXPos = ""
- txtVertYPos = ""
- POLARDraw1.ActivePage.Shapes.Delete
- End If
- End If
- Next
- End Sub
- Private Sub btnDelete_Click()
- 'Deletes selected polygons.
- 'On Error Resume Next
- If POLARDraw1.ActivePage.Selection.ShapeRange.Count = 0 Then
- MsgBox "Nothing is selected."
- Exit Sub
- End If
- If (myPoly Is Nothing) Then
- POLARDraw1.ActivePage.Selection.ShapeRange.Delete
- Else
- For Each element In POLARDraw1.ActivePage.Selection.ShapeRange
- If (element.ID = myPoly.ID) Then
- Set myPoly = Nothing
- txtVertCount = ""
- txtVertexIndex = ""
- txtVertXPos = ""
- txtVertYPos = ""
- POLARDraw1.ActivePage.Selection.ShapeRange.Delete
- Exit Sub
- End If
- Next
- POLARDraw1.ActivePage.Selection.ShapeRange.Delete
- End If
- End Sub
- Private Sub btnMoveMinus_Click()
- 'Moves specified vertex left and up for 2000 measurement units.
- If (myPoly Is Nothing) Then Exit Sub
- myVertex.Move -2000, -2000
- txtVertXPos = myVertex.x
- txtVertYPos = myVertex.y
- End Sub
- Private Sub btnMovePlus_Click()
- 'Moves specified vertex right and down for 2000 measurement units.
- If (myPoly Is Nothing) Then Exit Sub
- myVertex.Move 2000, 2000
- txtVertXPos = myVertex.x
- txtVertYPos = myVertex.y
- End Sub
- Private Sub btnPolygonInfo_Click()
- 'Calculates polygon info for first of selected shapes
- 'and colores that polygon in blue.
- If (POLARDraw1.ActivePage.Selection.ShapeRange.Count = 0) Then
- 'If nothing is selected, there is a message:
- MsgBox "Please select polygon."
- Else
- If (POLARDraw1.ActivePage.Selection.ShapeRange.Item(1).Type <> 0) Then
- 'If first of selected shapes is not polygon, then it's colored in red and
- 'appropriate message pops out.
-
- 'Item(1) specifies shape in selection that is most backward by Z-order.
- Set myShape = POLARDraw1.ActivePage.Selection.ShapeRange.Item(1)
- myShape.Line.Color = vbRed
- 'Specified shape gets on front by Z-order (so next time he may not be Item(1)of the same selection!).
- myShape.ZOrder (polBringToFront)
-
- MsgBox "Please convert red shape to polygon if you want to get it's vertices."
- Else
- 'If at least one polygon is selected,
- 'first of selected polygons is colored in blue.
- '(Polygon info will be calculated for that shape.)
- 'First all polygons on active page are colored in black:
- POLARDraw1.ActivePage.Shapes.Range.Line.Color = vbBlack
-
- 'Item(1) specifies shape in selection that is most backward by Z-order.
- POLARDraw1.ActivePage.Selection.ShapeRange.Item(1).Line.Color = vbBlue
- IsCalculatedPolygonInfo = True
-
- 'Object myPoly is polygon we set info for.
- Set myPoly = POLARDraw1.ActivePage.Selection.ShapeRange.Item(1)
-
- 'Shape myPoly gets on front by Z-order (so next time he may not be Item(1)of the same selection!).
- myPoly.ZOrder (polBringToFront)
-
- 'Object myVertices represents all vertices of myPoly.
- Set myVertices = myPoly.Vertices
-
- 'By default is provided info for fist vertex of selected polygon:
- ItemIndex = 1
- 'myVertex is Vertex object and represents one vertex of polygon
- 'which has been specified by it's index in Verticies collection.
- Set myVertex = myVertices.Item(ItemIndex)
- txtVertCount = myVertices.Count
- txtVertexIndex = ItemIndex
-
- txtVertXPos = myVertex.x
- txtVertYPos = myVertex.y
-
- End If
- End If
- End Sub
- Private Sub btnReCalculate_Click()
- 'Recalculates vertex x and y positions.
- 'It's recommended to use after moving vertex by mouse.
- If (myPoly Is Nothing) Then Exit Sub
- txtVertXPos = myVertex.x
- txtVertYPos = myVertex.y
- End Sub
- Private Sub bttnConvertToPolygon_Click()
- If (POLARDraw1.ActivePage.Selection.ShapeRange.Count = 0) Then
- MsgBox "Please select shape you want to convert to polygon."
- Else
- For Each element In POLARDraw1.ActivePage.Selection.ShapeRange
- If (element.Line.Color = vbRed) Then
- element.Line.Color = vbBlack
- End If
- element.ConvertToPolygon
- 'If myPoly is Curved-type polygon, then he also will be changed with ConvertToPolygon function.
- If (Not myPoly Is Nothing) Then
- If (POLARDraw1.ActivePage.Selection.ShapeRange.Item(1).ID = myPoly.ID) Then
- myPoly.ConvertToPolygon
- btnPolygonInfo_Click
- End If
- End If
- Next
- End If
- End Sub
- Private Sub cmbEditMode_Click()
- 'Sets Edit Mode.
- pd_environment.EditMode = cmbEditMode.ItemData(cmbEditMode.ListIndex)
- End Sub
- Private Sub cmbPolygonType_Click()
- 'Sets polygon type.
- pd_environment.CurrentPolygonType = cmbPolygonType.ItemData(cmbPolygonType.ListIndex)
- End Sub
- Private Sub cmbShapeType_Click()
- 'Sets shape type.
- pd_environment.CurrentShapeType = cmbShapeType.ItemData(cmbShapeType.ListIndex)
- If (POLARDraw1.CurrentShapeType <> polFreeform) Then
- cmbPolygonType.Enabled = False
- Else
- cmbPolygonType.Enabled = True
- End If
- End Sub
- Private Sub connectors_Click(Index As Integer)
- If connectors(1).Checked = False Then
- connectors(1).Checked = True
- POLARDraw1.ShowConnectors = True
- Else
- connectors(1).Checked = False
- POLARDraw1.ShowConnectors = False
- End If
- End Sub
- Private Sub draw_Click(Index As Integer)
- POLARDraw1.AboutBox
- End Sub
- Private Sub Form_Load()
- POLARDraw1.EditMode = polCreateNew
- POLARDraw1.CurrentShapeType = polFreeform
- POLARDraw1.CurrentPolygonType = polFreeformPoly
- POLARDraw1.UndoSize = 0
- POLARDraw1.ActiveWindow.FitTo polFitToWidth
- 'By default, guidelines are not visible.
- POLARDraw1.ActivePage.HorGuidelines.Add 15
- POLARDraw1.ActivePage.HorGuidelines.Add 302
- POLARDraw1.ActivePage.VertGuidelines.Add 15
- POLARDraw1.ActivePage.VertGuidelines.Add 185
- guidelines(1).Checked = False
- POLARDraw1.ShowGuidelines = False
- 'By default, connectors are not visible.
- connectors(1).Checked = False
- POLARDraw1.ShowConnectors = False
- 'By default, grid is not visible.
- POLARDraw1.ShowGrid = False
- IsCalculatedPolygonInfo = False
- arr_PolygonTypeConstants = Array(polCurvePoly, polFreeformPoly, polScribblePoly)
- arr_PolygonTypeNames = Array("Curved Polygon", "Free Form Polygon ", "Scribbled Polygon")
- arr_EditModeConstants = Array(polCreateNew, polEditPoints, polResize, polRotate)
- arr_EditModeNames = Array("Create New Shape", "Edit Points", "Resize", "Rotate")
- arr_ShapeTypeConstants = Array(polArc, polDiamond, polDimensionBar, polEllipse, polFreeform, polHexagon, polIsoscelesTriangle, polLeftArrow, polLine, polLink, polOctagon, polParallelogram, polPentagon, polPlainText, polPlusSign, polRectangle, polRightTriangle, polRoundRectangle, polStar, polTextBox, polTrapezoid)
- arr_ShapeTypeNames = Array("Arc", "Diamond", "Dimension Bar", "Ellipse", "Freeform", "Hexagon", "Isosceles Triangle", "Left Arrow", "Line", "Link", "Octagon", "Parallelogram", "Pentagon", "Plain Text", "Plus Sign", "Rectangle", "Right Triangle", "Round Rectangle", "Star", "Text Box", "Trapezoid")
- For i = 0 To UBound(arr_PolygonTypeConstants)
- cmbPolygonType.AddItem arr_PolygonTypeNames(i), i
- cmbPolygonType.ItemData(i) = arr_PolygonTypeConstants(i)
- Next i
- For i = 0 To UBound(arr_EditModeConstants)
- cmbEditMode.AddItem arr_EditModeNames(i), i
- cmbEditMode.ItemData(i) = arr_EditModeConstants(i)
- Next i
- For i = 0 To UBound(arr_ShapeTypeConstants)
- cmbShapeType.AddItem arr_ShapeTypeNames(i), i
- cmbShapeType.ItemData(i) = arr_ShapeTypeConstants(i)
- Next i
- Set pd_environment = POLARDraw1.ActiveWindow.Environment
- pd_environment.CurrentShapeType = polFreeform
- pd_environment.CurrentPolygonType = polFreeformPoly
- pd_environment.EditMode = polCreateNew
- For i = 0 To UBound(arr_PolygonTypeConstants)
- If cmbPolygonType.ItemData(i) = pd_environment.CurrentPolygonType Then cmbPolygonType.ListIndex = i
- Next i
- For i = 0 To UBound(arr_EditModeConstants)
- If cmbEditMode.ItemData(i) = pd_environment.EditMode Then cmbEditMode.ListIndex = i
- Next i
- For i = 0 To UBound(arr_ShapeTypeConstants)
- If cmbShapeType.ItemData(i) = pd_environment.CurrentShapeType Then cmbShapeType.ListIndex = i
- Next i
- End Sub
- Private Sub Form_Unload(Cancel As Integer)
- Set pd_environment = Nothing
- Set myVertices = Nothing
- Set myVertex = Nothing
- Set myPoly = Nothing
- Set myShape = Nothing
- End Sub
- Private Sub grid_Click(Index As Integer)
- If grid(1).Checked = False Then
- grid(1).Checked = True
- POLARDraw1.ShowGrid = True
- Else
- grid(1).Checked = False
- POLARDraw1.ShowGrid = False
- End If
- End Sub
- Private Sub guidelines_Click(Index As Integer)
- If guidelines(1).Checked = False Then
- guidelines(1).Checked = True
- POLARDraw1.ShowGuidelines = True
- Else
- guidelines(1).Checked = False
- POLARDraw1.ShowGuidelines = False
- End If
- End Sub
- Private Sub POLARDraw1_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
- 'When you add new vertex of polygon by mouse,
- 'count of vertices and vertex x and y positions need to be updated.
- If (POLARDraw1.ActivePage.Selection.ShapeRange.Count > 0) And (IsCalculatedPolygonInfo = True) Then
- If (myPoly Is Nothing) Then Exit Sub
-
- txtVertCount = myVertices.Count
- txtVertXPos = myVertex.x
- txtVertYPos = myVertex.y
-
- End If
- End Sub
- Private Sub sample_Click(Index As Integer)
- AboutDlg.show vbModal, Me
- End Sub
- Private Sub txtVertexIndex_Change()
- 'You can change vertex index by hand.
- If (myPoly Is Nothing) Then
- txtVertexIndex = ""
- Exit Sub
- End If
- Dim iCounter As Integer
- Dim iLen As Integer
- Dim iCountFromLeft As Integer
- Dim iCounterFromLeft As Integer
- Dim myString As String
- Dim myChar As Variant
- iLen = Len(txtVertexIndex)
- iCountFromLeft = 1
- 'Assurance that vertex index is numeric value.
- For iCounter = 1 To iLen
- For iCounterFromLeft = 1 To iCountFromLeft
- myString = Left(txtVertexIndex, iCountFromLeft)
- Next iCounterFromLeft
- myChar = Right(myString, 1)
- If (IsNumeric(myChar) = False) Then
- MsgBox "Index must be numeric value."
- Exit Sub
- End If
- iCountFromLeft = iCountFromLeft + 1
- Next iCounter
- 'Vertex index must be (>=1) and (<=count of vertices of that polygon).
- If txtVertexIndex = "" Then
- txtVertexIndex = 1
- ElseIf txtVertexIndex = 0 Then
- txtVertexIndex = 1
-
- Else
- If (CInt(txtVertexIndex) > myVertices.Count) Then
- MsgBox "Vertex index must be <= " + CStr(myVertices.Count)
- txtVertexIndex = ItemIndex
- Else
- ItemIndex = txtVertexIndex
-
- Set myVertex = myVertices.Item(ItemIndex)
- txtVertXPos = myVertex.x
- txtVertYPos = myVertex.y
-
- End If
- End If
- End Sub
- Private Sub txtVertXPos_Change()
- 'You can change vertex x position by hand.
- If (myPoly Is Nothing) Then
- txtVertXPos = ""
- Exit Sub
- End If
- Dim iCounter As Integer
- Dim iLen As Integer
- Dim iCountFromLeft As Integer
- Dim iCounterFromLeft As Integer
- Dim myString As String
- Dim myChar As Variant
- iLen = Len(txtVertXPos)
- iCountFromLeft = 1
- 'Assurance that vertex x position is numeric value.
- For iCounter = 1 To iLen
- For iCounterFromLeft = 1 To iCountFromLeft
- myString = Left(txtVertXPos, iCountFromLeft)
- Next iCounterFromLeft
- myChar = Right(myString, 1)
- If (IsNumeric(myChar) = False) Then
- MsgBox "Index must be numeric value."
- Exit Sub
- End If
- iCountFromLeft = iCountFromLeft + 1
- Next iCounter
- 'Vertex x position must be (>0) and (<65536).
- If (txtVertXPos = "") Then
- txtVertXPos = 0
- Set myVertex.x = txtVertXPos
- Else
- If (txtVertXPos > 65536) Then
- MsgBox "Vertex x position must be <= 65536)."
- Else
- Set myVertex.x = txtVertXPos
- End If
- End If
- End Sub
- Private Sub txtVertYPos_Change()
- 'You can change vertex y position by hand.
- If (myPoly Is Nothing) Then
- txtVertYPos = ""
- Exit Sub
- End If
- Dim iCounter As Integer
- Dim iLen As Integer
- Dim iCountFromLeft As Integer
- Dim iCounterFromLeft As Integer
- Dim myString As String
- Dim myChar As Variant
- iLen = Len(txtVertYPos)
- iCountFromLeft = 1
- 'Assurance that vertex y position is numeric value.
- For iCounter = 1 To iLen
- For iCounterFromLeft = 1 To iCountFromLeft
- myString = Left(txtVertYPos, iCountFromLeft)
- Next iCounterFromLeft
- myChar = Right(myString, 1)
- If (IsNumeric(myChar) = False) Then
- MsgBox "Index must be numeric value."
- Exit Sub
- End If
- iCountFromLeft = iCountFromLeft + 1
- Next iCounter
- 'Vertex y position must be (>0) and (<65536).
- If (txtVertYPos = "") Then
- txtVertYPos = 0
- Set myVertex.y = txtVertYPos
- Else
- If (txtVertYPos > 65536) Then
- MsgBox "Vertex y position must be <= 65536)."
- Else
- Set myVertex.y = txtVertYPos
- End If
- End If
- End Sub
-