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:
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).
I found now a solution, that reacts sufficiently fast to hoovering areas with the mouse.
The Main pictures is drawn in a PictureBox
instance, in more detail its property Image
is assigned.
The SizeMode
property 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 Picturebox
instance 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.
What to do, to implement my solution:
PictureBox
instance.
Image
propertyPicturebox
instances as form fieldAt assignment of a newly calculated image to the parent Picturebox
instance:
PictureBox
instance for each map area and add it to a list.
PictureBox
instance as a child control.Tag
property points to a data object containing the origin map bounds and the object represented by the rectangular map area.Picturebox
instance, that it suits the automatically zoomed image.Visible
to falseIn the parent Picturebox
instance the mouse over event handler does:
Picturebox
instance, where the mouse points atPicturebox
invisibleIn the parent Picturebox
instance the resize event handler does:
Picturebox
instances according to the bounds of the parent image and the bounds of the parent Picturebox
instance.The mouse leave event of each map area Picturebox
instance set itself invisible (losses of events previously mentionned).
The mouse click event of each map area Picturebox
instance makes whatever shall be done by clicking the map area.
Here playing a sine tone of the right chromatic pitch.
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 Picturebox
instances) 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 Bound
property in the resize event handler of the parent PictureBox
.
And the invisible action has been enabled for the map areas.