S
ShakeDoctor
Hi, In my custom control's OnPaint method, I'm drawing a filled polygon to
an offscreen buffer like so:
Bitmap _bmp = new Bitmap(ClientSize.Width, ClientSize.Height);
Graphics gr = Graphics.FromImage(_bmp);
gr.Clear(Color.White);
SolidBrush brush = new SolidBrush(Color.FromArgb(100, 255, 255));
gr.FillPolygon(brush, poly.Points);
Then, in my OnMouseDown method, i'm trying to determine if the user clicked
on the polygon by checking the colour at the point where they clicked like
so:
protected override void OnMouseDown(MouseEventArgs e)
{
Color col = _bmp.GetPixel(e.X, e.Y);
if (col != Color.White)
{
if (col == Color.FromArgb(100, 255, 255))
{
// polygon clicked
}
}
}
However, _bmp.GetPixel() returns 248 when you click on an area of the bitmap
which isn't the polygon (instead of 255), and 96 when you click on the
polygon (instead of 100).
Why is this?? and how can I get round it to detect when the user has
clicked the polygon??
TIA.
an offscreen buffer like so:
Bitmap _bmp = new Bitmap(ClientSize.Width, ClientSize.Height);
Graphics gr = Graphics.FromImage(_bmp);
gr.Clear(Color.White);
SolidBrush brush = new SolidBrush(Color.FromArgb(100, 255, 255));
gr.FillPolygon(brush, poly.Points);
Then, in my OnMouseDown method, i'm trying to determine if the user clicked
on the polygon by checking the colour at the point where they clicked like
so:
protected override void OnMouseDown(MouseEventArgs e)
{
Color col = _bmp.GetPixel(e.X, e.Y);
if (col != Color.White)
{
if (col == Color.FromArgb(100, 255, 255))
{
// polygon clicked
}
}
}
However, _bmp.GetPixel() returns 248 when you click on an area of the bitmap
which isn't the polygon (instead of 255), and 96 when you click on the
polygon (instead of 100).
Why is this?? and how can I get round it to detect when the user has
clicked the polygon??
TIA.