Making Hot Spots on Windows form using transparent buttons??

B

BobAchgill

The needed capability:
I guess there are two possibilities for making "hot
spots" on a Windows Form:

The Scenario:
I have a world map as the form background. I need
clickable hotspots over portions of the world map that
also have tool tip messages.

The Possibilities?:
Option 1:
Place invisible buttons on the area needing a hotspot.
Is this possible to make buttons invisible?

Option 2:
Put the buttons on a separate form of the same size as
the first and set the property of this form to 0%. Then
write code to overlay the form with buttons exactly on
top of the first form needing hotspots...so the world map
is viewable "under" the buttons. Is there sample code
that already does this? Seems a little messy for cases
when the user starts moving forms around. trying to keep
the two on top of one another.

Any other suggestions??
 
H

Herfried K. Wagner [MVP]

BobAchgill said:
The needed capability:
I guess there are two possibilities for making "hot
spots" on a Windows Form:

The Scenario:
I have a world map as the form background. I need
clickable hotspots over portions of the world map that
also have tool tip messages.

Option 3:

Add a handler to a form's (or control's) mouse events and store an
array/collection of regions that represent the hotspots. You can create
regions of arbitrary shape from a 'GraphicsPath' (see 'Region' constructor).
In the 'MouseUp' event, you loop through the regions and check 'IsVisible'
for the mouse position. In the mouse move event, you do the same and adjust
the tooltip's text accordingly. In addition to that, you'll have to provide
keyboard access to the regions.
 
B

BobAchgill

I lost you "on loop through the regions and
check 'IsVisible' for the mouse position.

Can you steer me to some example remotely like what you
are talking about?

I forgot I also need the feature AccessibleName that
would have come with using an invisible button approach.
I guess that will look something like:
Me.graphicspath.AccessibleName = "MyName"


I think I will be a better programmer after doing it the
way you are suggesting. If I can make it up that little
hill.

I have been wanting to do some thing with graphics so I
guess this is the beginning.

Thanks!
 
L

Larry Serflaten

BobAchgill said:
Option 2:
Put the buttons on a separate form of the same size as
the first and set the property of this form to 0%. Then
write code to overlay the form with buttons exactly on
top of the first form needing hotspots...
Any other suggestions??

Option 4
Create a bitmap of the world map such that hotspots are
different colors that helps to index them in an array of
informative items. As the user moves over the world map,
use the X and Y coordinates to get the pixel color information
from the indexed bitmap, and use that index to get information
about the hotspot.

For example, hotspot1 could be colored RGB(0, 0, 1),
hotspot2 = RGB(0, 0, 2), etc... and converting those colors
to indexes, you could look up the needed info from an array.

LFS
 
H

Herfried K. Wagner [MVP]

BobAchgill said:
I lost you "on loop through the regions and
check 'IsVisible' for the mouse position.

\\\
Private m_Regions() As Region
..
..
..
m_Regions = ...
..
..
..
Private Sub Form_MouseMove( _
ByVal sender As Object, _
ByVal e As MouseEventArgs _
) Handles MyBase.MouseMove
For Each r As Region In m_Regions
If r.IsVisible(e.X, e.Y) Then
RegionClicked(r)
Return
End If
Next r
End Sub
///
I forgot I also need the feature AccessibleName that
would have come with using an invisible button approach.
I guess that will look something like:
Me.graphicspath.AccessibleName = "MyName"

Mhm... I currently don't have an idea because the approach described above
doesn't make use of controls.
 
H

Herfried K. Wagner [MVP]

Larry Serflaten said:
Create a bitmap of the world map such that hotspots are
different colors that helps to index them in an array of
informative items. As the user moves over the world map,
use the X and Y coordinates to get the pixel color information
from the indexed bitmap, and use that index to get information
about the hotspot.

Good idea. That works pretty well and is easy to implement. I once
implemented that in VB6 ;-). Still the developer has to care about
accessibility (texts, keyboard access, ...).
 
N

Neil Wallace

BobAchgill wrote:
(sniP)
Put the buttons on a separate form of the same size as
the first and set the property of this form to 0%.

I thought the lowest value for for transparency was 50%.

and I still haven't thought of a reason to use it!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top