I am saving the extents of a control on a WinForm in a dictionary such as:
Dictionary<Tuple<int, int>, Control> dictionary =
new Dictionary<Tuple<int, int>, Control>();
And I am drawing controls on the WinForm programmatically. Whenever I draw each control I save the bounds of that control in this dictionary such as:
dictionary.Add(Tuple.Create(myControl.X, myControl.Y), myControl);
dictionary.Add(Tuple.Create(myControl.X + myControl.Length, myControl.Y), myControl);
dictionary.Add(Tuple.Create(myControl.X + myControl.Length, myControl.Y + myControl.Width), myControl);
dictionary.Add(Tuple.Create(myControl.X, myControl.Y + myControl.Width), myControl);
Now, what I want to achieve is that whenever there is a mouse click on the WinForm for MouseEventArgs e, I want to check whether Point(e.X, e.Y) lies within the bounds of a control or not??
I am aware that I can iterate through the Key value pairs of the dictionary and calculate whether the Point(e.X,e.Y) lies within the bound or not. But I want to avoid iterating through the Keys of the dictionary and get the solution.
Any idea how I can achieve it without iterating through the dictionary and calculate for each point?