Tooltip out of bounds of map

Topics: Windows Forms
Oct 23, 2012 at 8:00 AM


When moving mouse on markers, if the markers are on the edge of the map then the tooltip is shown half inside the map and half outside the map bounds.

How can i achieve the result by moving the tooltip to the other side of the map where there is more space to do that?

i don't find anything which can help.


thanks in advance

Jan 15, 2014 at 4:15 PM

Is anybody knows a solution yet?

Jan 20, 2014 at 1:14 PM
Edited Jan 9 at 8:46 AM
I've implemented it in my program Journey Plotter by extending the GMapTooltip class.
Perhaps this works for you too.
public override void OnRender(Graphics g)
  System.Drawing.Size st = g.MeasureString(Marker.ToolTipText, Font).ToSize();
  System.Drawing.Rectangle rect = new System.Drawing.Rectangle(Marker.ToolTipPosition.X, Marker.ToolTipPosition.Y - st.Height, st.Width + TextPadding.Width * 2, st.Height + TextPadding.Height);

  // Only draw tooltip if it fits withing the viewport
  if ((rect.Width < g.VisibleClipBounds.Width) && (rect.Height < g.VisibleClipBounds.Height))
    Point hotspot = new Point();

    rect.Offset(Offset.X, Offset.Y);

    if (rect.Right <= g.VisibleClipBounds.Right)
      // Tooltip fits within view port, use bottom-left corner as hotspot
      hotspot.X = rect.X + (int) (Radius / 2);
      // Shift tooltip left and use bottom-right corner as hotspot
      rect.Offset(-2 * Offset.X - rect.Width, 0);
      hotspot.X = rect.Right - (int) (Radius / 2);

    if (rect.Top < g.VisibleClipBounds.Top)
      // Shift tooltip down and use top-right corner as hotspot
      rect.Offset(0, 2 * rect.Height);
      hotspot.Y = rect.Top + (int) (Radius / 2);
      // Tooltip fits within view port, use top-left corner as hotspot
      hotspot.Y = rect.Bottom - (int) (Radius / 2);

    // Draw line from marker to tooltip hotspot
    g.DrawLine(Stroke, Marker.ToolTipPosition.X, Marker.ToolTipPosition.Y, hotspot.X, hotspot.Y);
    // Draw tooltip outline
    DrawRoundRectangle(g, Stroke, rect.X, rect.Y, rect.Width, rect.Height, Radius);
    // Draw tooltip text
#if !PocketPC
    if (Format.Alignment == StringAlignment.Near)
      rect.Offset(TextPadding.Width, 0);
    g.DrawString(Marker.ToolTipText, Font, Foreground, rect, Format);
    g.DrawString(ToolTipText, ToolTipFont, TooltipForeground, rect, ToolTipFormat);
Jan 20, 2014 at 3:04 PM
Hi Lekiam,

Thanks for your reply.

Can you please tell me where are you declaring the Radius and the DrawRoundRectangle function or I might have missed someting?
Also the last line is grayed out in my code, is it need to be?
g.DrawString(ToolTipText, ToolTipFont, TooltipForeground, rect, ToolTipFormat);

Do you have any workraound for overlapping toolips?

Many Thanks,
Jan 20, 2014 at 5:48 PM
Sorry my mistake, in my previous post instead of extending I meant inheriting.
I only showed you the rendering of the tooltip, the rest I left to your imagination.

You could check the GMapRoundedToolTip source code, it's mainly based on that.

The grey line is because of a symbol condition isn't met.
You would need to define the symbol PocketPC.
You'll notice the line of code is incorrect though, but I left it as is since I don't use PocketPC.

I've never looked at overlapping problems, so no solution for you there.
Jan 21, 2014 at 8:17 AM
Thanks Lekiam,

It's works nicely. Good job!!!

Oct 7, 2014 at 9:31 AM
Works very nice! Thanks a lot!