المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : How to Select Drawn Objects Without Getting a System.Windows.Forms.Control



C# Programming
01-19-2010, 04:40 PM
Hey everyone!

This is my first question that I've asked on this forum. I'm a fairly experienced C# coder who has browsed this site but never posted anything.

My question is simple, fairly straight forward. I would like to be able to select an object I have drawn with the System.Drawing.Graphics class. I would like to know how I could process the drawn-on control's MouseDown event so that the program can detect which objects have been drawn

this.CreateGraphics().DrawLine(new Pen(Color.Blue) { Width = 2.5f }, new Point(0, 0), new Point(50, 150));

This kind of drawing. I don't want to create a new control for every object being drawn on the screen, unless of course there is some way of doing it that doesn't hamper performance.

I have 2 ideas, but they aren't efficient enough, especially with a managed ******** such as C#. It is as follows: the program stores the information of which points inside the control are painted on. For example, the software could know that there is a blue pixel at point (20; 40). If the MouseDown event has to process every point, than I would imagine this method is extremely inefficient. Also, working out the area of a completely irregularly shaped object would be possible, but not in this case considering there are going to be user-defined/created objects drawn on screen.

Any advice on how I should do this? Any advice would be very helpful. Code samples would be a huge help.

Thanks A Lot,

Genius Mchlahla, (Amateur South African Programmer)