Re: Drawing graphics and responding to events

Peter Osucha <[email protected]>
Newsgroups gmane.comp.windows.devel.dotnet.winforms
Message-ID <[email protected]>
John,

Gotcha.  There is a column and row header that has a size different from
the circles - but I can account for that and still do what you
suggested.

Thanks.
Peter

-----Original Message-----
From: Discussion forum for developers using Windows Forms to build apps
and controls [mailto:[email protected]] On Behalf Of
John Brett
Sent: Wednesday, April 25, 2007 12:06 PM
To: [email protected]
Subject: Re: [DOTNET-WINFORMS] Drawing graphics and responding to events

> Thanks for the reply.  The case I have is a very simple one - all the
> shapes are on a grid and there is no overlap.  The circles cannot be
> moved at runtime.


You should be able to identify the candidate circle programmatically, in
that case - i.e. work out the grid cell the mouse occupies, and then do
a single comparison to find out if it is within the circle.

So you'd adjust your mouse location to be relative to the top left of
the
grid, then divide by the grid size, rounding down. This will give you
the
grid reference for the mouse, then you can use the method I posted
earlier
to calculate the distance between the mouse and the centre of the
circle.

More air-code:

Point mousePos;
mousePos = mousePos - gridRectangle.TopLeft;

int gridX= mousePos.X / gridSize.X;
int gridY= mousePos.Y / gridSize.Y;

Circle c= m_Circles[gridX][gridY];

&c.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.