|
Source Code: frmShape.frm |
Top Previous |
|
frmShape.frm is a VB6 form file that implements the main Shape Name Utility modal dialog box. It also manages the shape name query and update. The form is visually defined to look like this:
There are four global variables defined for the form. oApp and oMap define references to the MapPoint Application and Map. sName stores the name that was read from the current shape. bReadonly indicates if the name is read only (and should not be updated).
There are four methods, three of which are button call-backs.
AboutButton_Click
This is called when the user clicks the About button. It creates an About box (frmAbout) and opens it as a dialog box. frmAbout is implemented as a standard VB6-produced About box.
Private Sub AboutButton_Click() Dim dlg As frmAbout Set dlg = New frmAbout dlg.Show vbModal End Sub
CancelButton_Click
This is called when the user clicks the Cancel button. It simply closes the frmShape modal dialog box.
' Operation cancelled Private Sub CancelButton_Click() Unload Me End Sub
OKButton_Click
This is called when the user clicks the OK button. If saves any name change (if possible), and then closes the frmShape modal dialog box. Note that the new name is trimmed (leading and trailing spaces are removed) and compared against the stored copy of the shape name to check if it has changed.
Private Sub OKButton_Click() ' Update the name if it has changed If (Not bReadOnly) Then Dim sNewName As String sNewName = Trim$(boxName.Text) If (sNewName <> sName) Then Dim oShp As MapPoint.Shape Set oShp = oMap.Selection oShp.Name = sNewName End If End If Unload Me End Sub
DisplayForm
This is called by the Tools menu callback, to query the selected object's name and to display the form. Warning dialog boxes are displayed if an object is not selected, or if the object is not a shape or a pushpin. The name is read for both shape and pushpin selections, but pushpins are marked as readonly.
If the object is a shape, then the shape type is queried. Both the name and the type are displayed in the dialog before it is finally displayed.
' This is the actual guts of the program ' Find the selected object and query its name Public Sub DisplayForm(ByRef app As MapPoint.Application) Set oApp = app Set oMap = oApp.ActiveMap
bReadOnly = False
' Do we have a selected shape? If (oMap.Selection Is Nothing) Then MsgBox "No shape has been selected." & vbNewLine & "Please select a shape first.", vbOKOnly + vbInformation, "Shape Name Utility: No shape selected" Exit Sub End If
If (TypeOf oMap.Selection Is Pushpin) Then Dim oPin As MapPoint.Pushpin Set oPin = oMap.Selection
' Pushpins might be from an imported dataset, in which case it will be ' read only. Therefore we mark all pushpin names as readonly ' Note that a user can easily change the name of a pushpin through the ' MapPoint user interface, so this is not a significant restriction
sName = oPin.Name bReadOnly = True lblType.Caption = "Pushpin"
ElseIf (TypeOf oMap.Selection Is MapPoint.Shape) Then Dim oShp As MapPoint.Shape Dim nm As String Set oShp = oMap.Selection
With oShp sName = Trim$(oShp.Name) bReadOnly = False nm = "Shape (" If (oShp.Type = GeoShapeType.geoFreeform) Then nm = nm + "Freeform)" ElseIf (oShp.Type = GeoShapeType.geoLine) Then nm = nm + "Line)" ElseIf (oShp.Type = GeoShapeType.geoTextBox) Then nm = nm + "Text Box)" ElseIf (oShp.Type = GeoShapeType.geoAutoShape) Then If (oShp.AutoShapeType = GeoAutoShapeType.geoShapeOval) Then nm = nm + "Ellipse)" ElseIf (oShp.AutoShapeType = GeoAutoShapeType.geoShapeRadius) Then nm = nm + "Radius Circle)" ElseIf (oShp.AutoShapeType = GeoAutoShapeType.geoShapeRectangle) Then nm = nm + "Rectangle)" Else nm = nm + "Unknown Auto Shape)" End If Else nm = nm + "Unknown)" End If End With lblType.Caption = nm Else ' Selected object is not something we can handle MsgBox "Selected object is not a shape." & vbNewLine & "Please select a shape first.", vbOKOnly + vbInformation, "Shape Name Utility: Object is not a shape" Exit Sub End If
boxName.Text = sName boxName.Enabled = Not bReadOnly
Me.Show vbModal End Sub
|