I have a panel (here called parent), where I draw a calculated picture.
Some rectangular areas of this picture shall higlight by hoovering over.
It is the same behaviour like on a web page using , and , e. g.
the german map on the right upper side.
At hoovering the according rectangle shall be covered by a half transparent blue .
(And depending on keys like Alt, Ctrl and/or Shift in other colors, and clickable).
The first solution was a single instance of a transparent Panel – inherited from the Panel class.
In the hoovering event of the parent I moved and resized the single instance to the right place, changing the color.
This had some problems:
* moving and resizing (SetBounds()) fired MouseLeave event of the parent and a MouseEnter event of the single panel. The events had to be adapted accordingly to get it working correctly, I did it, but it is was very slow, due to finding the right map area from the list.
The second solution was to generate dynamically an instance of a transparent panel for each map area.
Each transparent panel had to set the e. g. Color.FromArgb(50, Color.Blue) at entering, and
remove it at leaving the panel.
But it seems to be even slower than before.
If the mouse hurries over several maps, they are all drawn like hoovered, and slowly get transparent again.
Does anybody know a good solution for this requirements:
- at picture resize in parent panel, map etc. has to be changed as well
- partly transparent highlight hoovered rectangle area.
- detection of Ctrl/Shift/Alt as events for an area and change of the color.
- detect click events there
Are there other controls I better use for this purpose?
Thanks for on practice based ideas.
PS: The world map with satellite pictures shows better what I want to do:
At hoovering the background is still visible more or less.
But in my case the parent image, its size and the maps are calculated at runtime
(after settings are completed by the user).
Solution
Description
I found now a solution, that reacts sufficiently fast to hoovering areas with the mouse.
The Main pictures is drawn in a
PictureBoxinstance, in more detail its propertyImageis assigned.The
SizeModeproperty is set to Zoom, that automatically centers and resizes the image with keeping the aspect ratio of the assigned image.I use a dynamically created
Pictureboxinstance for each map area (childs), that is invisible, if the mouse does not hoover over it.At hoovering over the map area the child shall appear – this is done in the mouse move event of the parent PictureBox,
where I iterate over the children, detecting whether the mouse position is in the bounds of a child.
The found child is set visible. Therefore the mouse enters this child control.
In the leave event of the child control I set it invisible again.
I experienced losses of mouse leave events for the child controls, if the mouse is moved too fast over all map areas.
I assume, if the mouse pointer already left the area before it has been set visible, the event is never raised.
The solution is, that all (other) child controls are set invisible, if in the mouse move event handler of the parent control does find no (a) child control.
Steps to implement
What to do, to implement my solution:
PictureBoxinstance.ImagepropertyPictureboxinstances as form fieldAt assignment of a newly calculated image to the parent
Pictureboxinstance:PictureBoxinstance for each map area and add it to a list.PictureBoxinstance as a child control.Tagproperty points to a data object containing the origin map bounds and the object represented by the rectangular map area.Pictureboxinstance, that it suits the automatically zoomed image.Visibleto falseIn the parent
Pictureboxinstance the mouse over event handler does:Pictureboxinstance, where the mouse points atPictureboxinvisibleIn the parent
Pictureboxinstance the resize event handler does:Pictureboxinstances according to the bounds of the parent image and the bounds of the parentPictureboxinstance.The mouse leave event of each map area
Pictureboxinstance set itself invisible (losses of events previously mentionned).The mouse click event of each map area
Pictureboxinstance makes whatever shall be done by clicking the map area.Here playing a sine tone of the right chromatic pitch.
Pictures
The pictures below show the prototype with the map areas (not yet correctly aligned, some offset):
The first picture is for illustration of parent picture and all map areas.
The main picture (scale) and all map areas (dynamically created child
Pictureboxinstances) are drawn in the first picture (by disabling the invisible action for map areas).The second image is productive, where the mouse hoovers over tone G4.
In the second image the form has been resized – therefore the parent image is automatically been centered and resized.
The map areas were simply changed in their
Boundproperty in the resize event handler of the parentPictureBox.And the invisible action has been enabled for the map areas.