Groups | Blog | Home
all groups > dotnet drawing api > march 2008 >

dotnet drawing api : How to tooltip and hyperlink a shape?


gnewsgroup
3/14/2008 7:22:55 AM
Quite many charting tools (such as dundas) create charts whose
components can display a tooltip when the cursor them. And the
components can also be hyperlinked.

If I am not make it clear, the following picture shows what I am
talking about.

http://farm3.static.flickr.com/2326/2333252986_1a6ba6d548_o.png

Now, how do we achieve such effects through .net graphics
programming? I searched around, but could not find anything helpful.

Mad-Hollander
3/14/2008 9:37:11 AM
Look at this code
All objects in my application are derived from PictureBase class.

interface IPicture
{
IShape Bounds {get;set;} // for clipping and mouse operations
Point Location {get;set;}

void Draw(Graphics gr);
void DrawDragged(Graphics gr);


IStyle Style{get; set;}
IState State{get; set;}

string Tip {get;set;}
CursorObject Cursor {get;set;}

void Think();
}

class PictureBase : IPicture // base class for all objects and
primitives
{
// to do
}

class View
{
// to do
void TrackMouseMove()
{
PictureBase htObj =3D CheckHitTest(m_lastMouseMovePos);
if(htObj =3D=3D null)
{
SetMousePointer(CurrentMode.Cursor);
return;
}
if (m_lastHoveredObj !=3D htObj) // another object under the mouse
{
m_tooltip.Active =3D false;
m_tooltip.SetToolTip(m_canvas, (htObj !=3D null) ? htObj.Tip : null);
m_tooltip.Active =3D (htObj !=3D null);
SetMousePointer(htObject.Cursor);
m_lastHoveredObj =3D htObj;
}
}
}


[quoted text, click to view]
gnewsgroup
3/14/2008 11:21:32 AM
[quoted text, click to view]

Hi,

Thank you very much. But, I have little graphics programming
experience. So would you mind explaining what each class and major
Mad-Hollander
3/17/2008 8:14:27 AM
[quoted text, click to view]


There is pseudocode of simplier version

abstract class PictureBase // base class for all objects
{
public Rectangle Bounds {get;set;} // contains the topleft
corner (position) of object and its width and height
// when your object has not a rectangle shape, you should
implement you own class for boundaries

public abstract void Draw(Graphics gr); // draws the content
and setup property Bounds
// example - if method draws a rectangle with size (10,10) at
point of topleft corner (100,100), you should use these values for
Bounds property.

public string Tip {get;set;} // the string for showing when
mouse is moving over the objec
public System.Windows.Forms.Cursor Cursor {get;set;} // the
cursor for using when mouse is moving over the object
}

class View // this is usercontrol or panel which contains a canvas
control or it is the class of canvas :-)
{
// to do

// this method shoul be called on each move move event
void TrackMouseMove()
{
// CheckHitTest - the method which uses
PictureBase.Bounds property and determines the object under the mouse
pointer.
//Usually it iterates through all objects and return
an object which Bounds contains mouse position.
PictureBase htObj =3D
CheckHitTest(m_lastMouseMovePos);
if(htObj =3D=3D null)
{
m_canvas.Cursor =3D m_defaultCursor; // set
default cursor
return;
}
if (m_lastHoveredObj !=3D htObj) // another object under
the mouse
{
m_tooltip.Active =3D false;
m_tooltip.SetToolTip(m_canvas, (htObj !=3D
null) ? htObj.Tip : null);
m_tooltip.Active =3D (htObj !=3D null);
m_canvas.Cursor =3D htObject.Cursor;
m_lastHoveredObj =3D htObj;
}
}
Jeff Johnson
3/17/2008 10:00:49 AM
[quoted text, click to view]

Tooltips are actually windows. As such, they have built-in functionality for
processing mouse messages, etc. I think you'd be better served trying to
implement your tips as a window rather than drawing directly on your control
and having to worry about mouse coordinates and stuff.

AddThis Social Bookmark Button