

| General Properties Methods Events Example |
This page contains the Visual Basic source code for the Demo Project. Below is a screenshot of the interface for reference. Clicking on various elements of the screenshot will take you directly to the relevant portion of code. You can also use the links below the screenshot to jump to the different Subs available.
Subs available:
Private Sub Form_Load() '==================================================== 'This is all the stuff we want to do to setup the 'Form before it is displayed. '==================================================== 'Simulate a click on the unchecked Show Hotspots 'checkbox to disable the hotspot coloring and 'draw mode options. chkShowHotspots_Click 'Set the default selected Draw Mode in the combo box 'to be the same as the one that was selected in the 'Properies Window. HotspotDrawMode starts with 1 '(BLACK) while the combobox index starts with zero, 'so subtract 1 to match it. cmbHotspotDrawMode.ListIndex = _ ImageMap1.HotspotDrawMode - 1 'Since Red was set as the default hotspot color in 'the Properties Window, highlight the red color box. lblColor_Click 9 'Set the CoordsFile to point to the file containing 'the map coordinates in HTML. This is done in code 'instead of the Properties Window in this case 'because I do not know the path to the file until 'the program is run. ImageMap1.CoordsFile = App.Path & "\objects.htm" 'Match the Coordinates File text area to the path 'of the file. txtCoordsFile.Text = ImageMap1.CoordsFile 'Set the Background Picture preview image to match 'the main picture (which was set using the Properties 'Window). imgBackgroundPicture.Picture = ImageMap1.Picture 'Set the HotspotMouseIcon preview image to match 'the icon in the HotspotMouseIcon property (which 'was set using the Properties Window). imgHSMouseIcon.Picture = ImageMap1.HotspotMouseIcon End Sub
Private Sub chkShowHotspots_Click() '==================================================== 'If the "Show Hotspots" checkbox is checked, show the 'hotspots and enable all of the controls related to 'color and draw mode. Otherwise, gray-out and disable 'all of the color and draw mode controls and make the 'hotpsots invisible. '==================================================== Dim X As Integer Select Case chkShowHotspots.Value Case vbChecked 'show the hotpots ImageMap1.ShowHotspots = True 'enable the color picker lblHotspotColor.ForeColor = vbButtonText For X = 0 To 15 lblColor(X).Enabled = True Next X 'enable the draw mode picker lblHotspotDrawMode.ForeColor = vbButtonText cmbHotspotDrawMode.Enabled = True Case vbUnchecked 'hide the hotspots ImageMap1.ShowHotspots = False 'disable the color picker lblHotspotColor.ForeColor = vbGrayText For X = 0 To 15 lblColor(X).Enabled = False Next X 'disable the draw mode picker lblHotspotDrawMode.ForeColor = vbGrayText cmbHotspotDrawMode.Enabled = False End Select End Sub
Private Sub cmbHotspotDrawMode_Click() '==================================================== 'Set the HotspotDrawMode to the option selected in 'the drop-down combobox. HotspotDrawMode starts with '1 (BLACK) while the combobox index starts with zero, 'so add 1 to match it. '==================================================== ImageMap1.HotspotDrawMode = _ cmbHotspotDrawMode.ListIndex + 1 End Sub
Private Sub cmdApplyCoordsFile_Click() '==================================================== 'Set the CoordsFile property to the path and file 'entered in the textbox. The ImageMap will then read 'the HTML file and create hotspots according to the '<map> and <area> tags found in it. '==================================================== ImageMap1.CoordsFile = txtCoordsFile.Text End Sub
Private Sub cmdApplyCoordsString_Click() '==================================================== 'Set the CoordsString property to the HTML that was 'entered in the textbox. The ImageMap will then 'create hotspots according to the <map> and <area> 'tags found in the HTML string. '==================================================== ImageMap1.CoordsString = txtCoordsString.Text End Sub
Private Sub cmdBrowseCoordsFile_Click() '==================================================== 'Show the Common Dialog so the user can select a file 'to use as the CoordsFile property. If they chose a 'file (i.e. did not cancel), automatically apply the 'filename to the CoordsFile property and update the 'textbox to reflect the new path/file. '==================================================== With CommonDialog1 .Flags = cdlOFNFileMustExist Or cdlOFNHideReadOnly .CancelError = False 'Allow them to select any file, because the 'CoordsFile can have any extension. .Filter = "All Files (*.*)|*.*" .ShowOpen 'If they cancelled, exit the sub. If .FileName = "" Then Exit Sub 'Apply the new filename to the CoordsFile 'property and update the textbox. ImageMap1.CoordsFile = .FileName txtCoordsFile.Text = .FileName End With End Sub
Private Sub cmdBrowseHSMouse_Click() '==================================================== 'Lets them pick a new mouse cursor for when the mouse 'is over a hotspot. See the SelectIcon Sub below for 'details. '==================================================== SelectIcon True End Sub
Private Sub cmdBrowseIMMouse_Click() '==================================================== 'Lets them pick a new mouse cursor for when the mouse 'is anywhere over the ImageMap. See the SelectIcon 'Sub below for details. '==================================================== SelectIcon False End Sub
Private Sub SelectIcon(bHotspot As Boolean) '==================================================== 'If bHotspot=True, then change the HotspotMouseIcon 'property, otherwise change the MouseIcon property. 'This Sub was made to reduce redundant code. '---------------------------------------------------- 'Show the Common Dialog so the user can select a 'cursor or icon that will be displayed when the mouse 'is anywhere over the ImageMap or over a hotspot, 'depending on the bHotspot parameter. If a new 'MouseIcon is selected, the cursor previously 'designated in the HotspotMouseIcon propery will 'still be displayed when the mouse is over a hotspot. 'If they chose a file (i.e. did not cancel), 'automatically apply the filename to the MouseIcon or 'HotspotMouseIcon property and update the preview 'image to reflect the new cursor. '==================================================== On Error GoTo InvalidIcon With CommonDialog1 .Flags = cdlOFNFileMustExist Or cdlOFNHideReadOnly .CancelError = False 'We only want icons or cursors, so only display 'those in the Common Dialog. .Filter = "Icons (*.ico;*.cur)|*.ico;*.cur" .ShowOpen 'If they cancelled, exit the sub. If .FileName = "" Then Exit Sub 'In case they picked something other than an icon 'or cursor (maybe by typing *.* into the filename), 'remind them that only icons and cursors are 'supported and tell them to try again. If LCase(Right$(.FileName, 4)) <> ".ico" And _ LCase(Right$(.FileName, 4)) <> ".cur" Then MsgBox ("Only icons (.ico) and cursors " & _ "(.cur) are supported. Please try again.") Exit Sub End If Select Case bHotspot Case True 'Apply the new filename to the HotspotMouseIcon 'property and update the preview image. Set ImageMap1.HotspotMouseIcon = _ LoadPicture(.FileName) Set imgHSMouseIcon = ImageMap1.HotspotMouseIcon Case False 'Apply the new filename to the MouseIcon 'property and update the preview image. Set ImageMap1.MouseIcon = _ LoadPicture(.FileName) Set imgIMMouseIcon = ImageMap1.MouseIcon End Select .FileName = "" End With Exit Sub 'If the LoadPicture failed, tell them to pick a 'different file and try again. InvalidIcon: MsgBox ("Invalid icon file. Please try again.") End Sub
Private Sub cmdBrowsePicture_Click() '==================================================== 'Show the Common Dialog so the user can select an 'image to be displayed as the background of the 'ImageMap. This is the image that is "mapped out". 'If they chose a file (i.e. did not cancel), 'automatically apply the filename to the Picture 'property and update the preview image to reflect the 'new picture. '==================================================== On Error GoTo InvalidPicture With CommonDialog1 .Flags = cdlOFNFileMustExist Or cdlOFNHideReadOnly .CancelError = False 'We only want graphic files, so only display 'those in the Common Dialog. .Filter = "All Pictures" + _ "|*.bmp;*.dib;*.jpg;*.jpeg;*.gif;*.wmf;" + _ "*.emf;*.ico;*.cur" + _ "|Bitmaps (*.bmp;*.dib)|*.bmp;*.dib" + _ "|GIF Images (*.gif)|*.gif" + _ "|JPEG Images (*.jpg;*.jpeg)|*.jpg;*.jpeg" + _ "|Metafiles (*.wmf;*.emf)|*.wmf;*.emf" + _ "|Icons (*.ico;*.cur)|*.ico;*.cur" + _ "|All Files (*.*)|*.*" .ShowOpen 'If they cancelled, exit the sub. If .FileName = "" Then Exit Sub 'Apply the new filename to the Picture 'property and update the preview image. Set ImageMap1.Picture = LoadPicture(.FileName) Set imgBackgroundPicture = ImageMap1.Picture .FileName = "" End With 'Make sure the form is large enough to fit the new 'picture (see Sub FormAutoSize below). FormAutoSize Exit Sub 'If the LoadPicture failed, tell them to pick a 'different file and try again. InvalidPicture: MsgBox ("Invalid picture file. Please try again.") End Sub
Private Sub chkAutoSize_Click() '==================================================== 'If the "Autosize" checkbox is checked, resize the 'control to fit the entire picture. Otherwise the 'picture will be clipped if it is larger than the 'control. '==================================================== Select Case chkAutoSize.Value Case vbChecked ImageMap1.AutoSize = True Case vbUnchecked ImageMap1.AutoSize = False End Select 'Make sure the form is large enough to fit the newly 'resized control (see Sub FormAutoSize below). FormAutoSize End Sub
Private Sub FormAutoSize() '==================================================== 'This routine will resize the form so that the entire 'ImageMap picture will be shown. '==================================================== Dim iWidth As Integer, iHeight As Integer On Error Resume Next iWidth = ImageMap1.Width + 4425 iHeight = ImageMap1.Height + 3030 'Make sure the form doesn't get too small 'in case the ImageMap picture is tiny If iWidth < 9285 Then iWidth = 9285 If iHeight < 6690 Then iHeight = 6690 Me.Width = iWidth Me.Height = iHeight End Sub
Private Sub chkBorder_Click() '==================================================== 'If the "Border" checkbox is checked, show the 3D 'border around the control, to give it that "sunken" 'look. '==================================================== ImageMap1.Border = chkBorder.Value End Sub
Private Sub cmdClearCoordsString_Click() '==================================================== 'Clear the CoordsString text area. '==================================================== txtCoordsString.Text = "" End Sub
Private Sub cmdClearHSMouse_Click() '==================================================== 'Clear the HotspotMouseIcon property and the preview 'image. The default mouse icon will be used when the 'mouse is over a hotspot. '==================================================== Set ImageMap1.HotspotMouseIcon = Nothing Set imgHSMouseIcon.Picture = Nothing CommonDialog1.FileName = "" End Sub
Private Sub cmdClearIMMouse_Click() '==================================================== 'Clear the MouseIcon property and the preview image. 'The default mouse icon will be used when the mouse 'is anywhere over the ImageMap, except for hotspots 'which will use whatever icon is designated in the 'HotspotMouseIcon property. '==================================================== Set ImageMap1.MouseIcon = Nothing Set imgIMMouseIcon.Picture = Nothing CommonDialog1.FileName = "" End Sub
Private Sub cmdClearPicture_Click() '==================================================== 'Clear the Picture property and preview image. The 'ImageMap will no longer have a background image. '==================================================== Set ImageMap1.Picture = Nothing Set imgBackgroundPicture.Picture = Nothing CommonDialog1.FileName = "" End Sub
Private Sub cmdPasteCoordsString_Click() '==================================================== 'Paste any text found on the clipboard into the 'CoordsString text area. '==================================================== txtCoordsString.Text = Clipboard.GetText End Sub
Private Sub cmdShowAbout_Click() '==================================================== 'Show the About dialog. Includes version number, 'support email, website, and order info for the 'ImageMap control. '==================================================== ImageMap1.ShowAboutBox End Sub
Private Sub ImageMap1_HotspotClick(HotspotID As _ String, X As Single, Y As Single) '==================================================== 'Add the Click event for this hotspot to the Last 'Events list. See the SetLastAction Sub below for 'details. '==================================================== SetLastAction HotspotID, "(Click)" End Sub
Private Sub ImageMap1_HotspotDblClick(HotspotID As _ String, X As Single, Y As Single) '==================================================== 'Add the DblClick event for this hotspot to the Last 'Events list. See the SetLastAction Sub below for 'details. '==================================================== SetLastAction HotspotID, "(DblClick)" End Sub
Private Sub ImageMap1_HotspotMouseDown(HotspotID As _ String, Button As Integer, Shift As Integer, X As _ Single, Y As Single) '==================================================== 'Add the MouseDown event for this hotspot to the Last 'Events list. See the SetLastAction Sub below for 'details. '==================================================== SetLastAction HotspotID, "(MouseDown)" End Sub
Private Sub ImageMap1_HotspotMouseUp(HotspotID As _ String, Button As Integer, Shift As Integer, X As _ Single, Y As Single) '==================================================== 'Add the MouseUp event for this hotspot to the Last 'Events list. See the SetLastAction Sub below for 'details. '==================================================== SetLastAction HotspotID, "(MouseUp)" End Sub
Private Sub SetLastAction(sHotspotID As String, _ sAction As String) '==================================================== 'Updates the Last Event listbox with the name of the 'hotspot and the action performed on it. Since all 'MouseMove events are triggered continuously, they 'are not displayed here because the list would scroll 'too fast to see the other events such as Click, 'MouseUp, MouseDown, etc. '==================================================== 'If the list is already full, remove the last one to 'make room for the new event. First-in-first-out. If List1.ListCount > 21 Then List1.RemoveItem _ List1.ListCount - 1 'Add the new hotspot name and event to the top of 'the list. List1.AddItem sHotspotID + " " + sAction, 0 End Sub
Private Sub ImageMap1_MouseMove(HotspotID As _ String, Button As Integer, Shift As Integer, _ X As Single, Y As Single) '==================================================== 'Set the "Mouse is over:" label caption to show which 'hotspot the mouse is currently moving over. '==================================================== Static sPrevID As String If HotspotID <> sPrevID Then lblMouseOverObject.Caption = HotspotID sPrevID = HotspotID End If End Sub
Private Sub lblColor_Click(Index As Integer) '==================================================== 'If the user clicks on any of the colors to set the 'hotspot color, highlight the color selected then 'change the HotspotColor property of the ImageMap to 'reflect the selected color. '==================================================== Dim lColor As Long, X As Integer 'First un-highlight all of the colors For X = 0 To 15 'When the Appearance of a label is changed, the 'BackColor gets reset to the default (ButtonFace), 'so store the current color so we can set it back 'after we change the Appearance. lColor = lblColor(X).BackColor lblColor(X).Appearance = 1 lblColor(X).BorderStyle = 1 'Set the BackColor back to what it was before. lblColor(X).BackColor = lColor Next X 'Get the BackColor of the selected label and set the 'HotspotColor property to it. lColor = lblColor(Index).BackColor ImageMap1.HotspotColor = lColor 'Now highlight the selected color lblColor(Index).Appearance = 0 lblColor(Index).BorderStyle = 1 lblColor(Index).BackColor = lColor End Sub