ObjectEnterLeave event not getting fired

Hi all,

I'm experiencing problem with ObjectEnterLeave event, here are the details:
I want to change color of a shape when mouse moves over the shape and When mouse moves away from the shape I want to reset color of the shape to original one. To achieve this functionality I'm using ObjectEnterLeave event. I want to implement this functionality (called Highlighting) on individual shape as well as on GoGroup (that can contain one or more shapes). The DocScale is set to less than 1, if that matters. The problems I'm experiencing are: 1. When Pen width is less than or equal to 0.25 then GoDiagram does not recognize mouse move over this shape and it does not raise ObjectEnterLeave event for respective shape.
2. Sometimes for vertical line also it does not recognize mouse move and does not raise ObjectEnterLeave event. I can provide sample code if required.
Thanks and Regards,

Yes, if you could send a small sample that duplicates the problem, that’s always a huge help.

Hi Jake,

Here is the code:
void goView1_ObjectEnterLeave(object sender, GoObjectEnterLeaveEventArgs e) { GoObject pFrom = e.From; GoObject pTo = e.To; if (pTo != null) { ((GoShape)pTo).PenColor = Color.Orange; } if (pFrom != null) { ((GoShape)pFrom).PenColor = Color.Black; } } private void button1_Click(object sender, EventArgs e) { GoDrawing pGDDrw = new GoDrawing(); pGDDrw.StartAt(new PointF((float)434.211456, (float)-492.410645)); pGDDrw.LineTo(new PointF((float)434.211456, (float)-231.78038)); pGDDrw.PenWidth = 0.25f; GoDrawing pGDDrw1 = new GoDrawing(); pGDDrw1.StartAt(new PointF((float)470, (float)-485)); pGDDrw1.LineTo(new PointF((float)470, (float)-220)); pGDDrw1.PenWidth = .3f;

goView1.DocScale = .6f;

goView1_ObjectEnterLeave is the event handler for ObjectEnterleave Event, and adding drawing objects code has been written in the button1_Click event handler. The line coordinates can be changed and are of little importance.

OK. You are creating an object that is smaller than the resolution of the mouse.

Mouse X 262 maps to doc X of 433.3333

Mouse X 263 maps to doc X of 434.9999

Your object (a very thin vertical line) has a Left X of 434.086 and a Right X of 434.336.

So, your object lives in the space between the 2 points reported by the mouse movement.

So, technically, Go is doing the right thing here, although not being able to do a hit test on an object you can see is a bit non-intuitive.

If you really want a PenWidth of .25, you’ll have to derive from GoDrawing and override ContainsPoint and add some code for “very very close”.

Hi Jake,

In your answer you have proposed to add some code for "very very close". Can you please elaborate on it, or it would be good if you can provide some code snippet for same.
Also, I experimented more with Go Diagrams, and I found some inconsistent behaviour. In the below code snippet, Shape 5 and 6 are still getting highlighted, even though their pen width is 0.25. While 1,2,3,4 are still not getting highlighted.
GoDrawing pGDDrw1 = new GoDrawing(); pGDDrw1.StartAt(new PointF((float)434.211456, (float)-492.410645)); pGDDrw1.LineTo(new PointF((float)434.211456, (float)-231.78038)); pGDDrw1.PenWidth = 0.25f; GoDrawing pGDDrw2 = new GoDrawing(); pGDDrw2.StartAt(new PointF((float)358.7006, (float)-492.410645)); pGDDrw2.LineTo(new PointF((float)358.7006, (float)-231.78038)); pGDDrw2.PenWidth = 0.25f;

GoDrawing pGDDrw3 = new GoDrawing();
pGDDrw3.StartAt(new PointF((float)358.7006, (float)-477.6309));
pGDDrw3.LineTo(new PointF((float)434.211456, (float)-477.6309));
pGDDrw3.PenWidth = 0.25f;

GoDrawing pGDDrw4 = new GoDrawing();
pGDDrw4.StartAt(new PointF((float)358.709381, (float)-232.21843));
pGDDrw4.LineTo(new PointF((float)434.2202, (float)-232.21843));
pGDDrw4.PenWidth = 0.25f;
GoDrawing pGDDrw5 = new GoDrawing();
pGDDrw5.StartAt(new PointF((float)200, (float)-232.21843));
pGDDrw5.LineTo(new PointF((float)250, (float)-232.21843));
pGDDrw5.LineTo(new PointF((float)250, (float)-282.21843));
pGDDrw5.PenWidth = 0.25f;

GoDrawing pGDDrw6 = new GoDrawing();
pGDDrw6.StartAt(new PointF((float)358.709381, (float)-232.2184));
pGDDrw6.CurveTo(new PointF((float)386.192535, (float)-198.155746), new PointF((float)418.047455, (float)-204.472412), new PointF((float)434.229, (float)-232.5601));
pGDDrw6.PenWidth = 0.25f;
goView1.DocScale = 1f;

I think this issue is related to my problem.Can you please explain this?

Imagine a sheet of grid paper with a 1/4" (quarter inch) grid. Now take a felt tip pen, shut your eyes, and make 6 random dots on the page.

The intersecting points on the grid paper are the coordinates returned by mouse move. The grid lines the locations where a “hit” would be detected.

If the dots you make on the paper intersect the lines, a “hit” would be detected by GoDiagram. If the dot doesn’t hit a line, it wouldn’t. That’s why you are seeing the behavior you are.

On further thought, it may be better to compute the bounding box of the line to be larger than it is than to change the hit test code.

I can have something for you later today.

Also consider that if there are several such figures very close to each other, only one of them will be pickable with the mouse. They are effectively on top of each other.

OK. First the code, then the caveat.


public class GoDrawingThin : GoDrawing {

protected override RectangleF ComputeBounds() {

RectangleF r = base.ComputeBounds();

if (r.Width == 0.0) {

float w = 1.7f;

r.X -= w/2;

r.Width = w;


return r;



The “distance” between pixels when you are at DocScale = .6 is 1.666. So, potentially, any object with less width than that can sit in the area between the pickable locations.

So, the value 1.7 in the code is actually bigger than it needs to be, since the .25 width of the Pen is added in when doing the hit test.

This also only handles vertical lines, I don’t handle Height == 0.

Now, the caveat: This value changes at different DocScales. At DocScale = .24, the distance is 4.1666.

This all makes sense… if you zoom out, things get smaller and smaller, the distance between objects on the screen gets smaller. It has to be harder to point at them individually. (this echos Walter’s comment above)

Notice our GoStroke class has a PickMargin property, which adds some width to lines over and above the PenWidth. This defaults to 3.

If you can switch to GoStoke from GoDrawing, you wouldn’t see this problem at DocScale .6.

But… I don’t understand your app, why you are using PenWidth of .25, why you are using GoDrawing for a line, or how much “zoom” would be expected. So these are the trade-offs you’ll have to make. I’m just here to explain how it works.

Hi Jake,

Thanks for you reply.I am trying if that helps.
Regarding your question, I am taking data from a proprietory file format and rendering it as such.There I am getting PenWidth of 0.25.So I cannot change the properties and have to render it as it is.
Why I am using GoDrawing for a line is because my shape gives me coordinates and these coordinates can be of curves or straight lines, so I cannot use any other Go class.

Excellent reasons then, I see why you’ve made those tradeoffs. Hopefully my code above gets you past this issue.