VB Downscaling coordinates <p>I have the need to know when a gdi+ drawn line is clicked on by the mouse.</p> <p>I have fashioned this function which is used in a loop on all the existing lines and what the function does is:</p> <ol> <li>It makes a buffer of the line's container's size</li> <li>It makes the whole thing black</li> <li>It draws the line in green </li> <li>It gets the pixel at the mouse location</li> <li>If the pixel is different from black a.k.a green, the line has successfully been clicked and the function should then return true.</li> </ol> <p>This works great, there's no misinterpretations, but I'm afraid that there's a tiny delay (not really noticeable) when my form is in full screen (due to the large buffer). </p> <p>I'm looking for a way to optimize this, and my first thought is to downscale everything. So what I mean by that is make the buffer like 20x20 and then draw the line in a scaled down version using math. Problem is, I suck at math, so I'm basically asking you how to do this and preferably with an explanation for dummies.</p> <p>This is the function:</p> <pre><code>Public Function Contains(ByVal e As Point) As Boolean Dim Width As Integer = Container.Size.Width Dim Height As Integer = Container.Size.Height Dim Buffer As Bitmap = New Bitmap(Width, Height) Using G As Graphics = Graphics.FromImage(Buffer) G.Clear(Color.Black) Dim Start As Point = New Point(ParentNode.Location.X + ParentNode.Size.Width / 2, ParentNode.Location.Y + ParentNode.Size.Height / 2) Dim [End] As Point = New Point(ChildNode.Location.X + ChildNode.Size.Width / 2, ChildNode.Location.Y + ChildNode.Size.Height / 2) Dim Control1 As Point Dim Control2 As Point Control1.X = Start.X + GetAngle(ChildNode.Location, ParentNode.Location, ChildNode.Location.X - ParentNode.Location.X, ChildNode.Location.Y - ParentNode.Location.Y) Control1.Y = Start.Y Control2.X = [End].X Control2.Y = Start.Y G.DrawBezier(New Pen(Color.Green, 4), Start, Control1, Control2, [End]) End Using If Buffer.GetPixel(e.X, e.Y).ToArgb() &lt;&gt; Color.Black.ToArgb() Then Return True End If Return False End Function </code></pre> <p>This is one of my attempts to make the function use the idea above:</p> <pre><code>Public Function Contains(ByVal e As Point) As Boolean Dim Width As Integer = 20 Dim Height As Integer = 20 Dim Buffer As Bitmap = New Bitmap(Width, Height) Using G As Graphics = Graphics.FromImage(Buffer) G.Clear(Color.Black) Dim Start As Point = New Point(ParentNode.Location.X + ParentNode.Size.Width / 2, ParentNode.Location.Y + ParentNode.Size.Height / 2) Dim [End] As Point = New Point(ChildNode.Location.X + ChildNode.Size.Width / 2, ChildNode.Location.Y + ChildNode.Size.Height / 2) Dim Control1 As Point Dim Control2 As Point Control1.X = Start.X + GetAngle(ChildNode.Location, ParentNode.Location, ChildNode.Location.X - ParentNode.Location.X, ChildNode.Location.Y - ParentNode.Location.Y) Control1.Y = Start.Y Control2.X = [End].X Control2.Y = Start.Y G.DrawBezier(New Pen(Color.Green, 4), New Point(Start.X / Width, Start.Y / Height), New Point(Control1.X / Width, Control1.Height / Height), New Point(Control2.X / Width, Control2.Y / Height), New Point([End].X / Width, [End].Y / Height)) End Using If Buffer.GetPixel(Width, Height).ToArgb() &lt;&gt; Color.Black.ToArgb() Then Return True End If Return False End Function </code></pre>