By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,815 Members | 1,143 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,815 IT Pros & Developers. It's quick & easy.

Advanced Events

P: n/a
Good Morning All,
I am working on a CAD application. At the time of this writing I am
currently working on the GraphicsEngine. The structure is as follows:

GraphicsObject (Base Class, Must Inherit)
ShapeObject (Must Inherit)
Derived Classes()
TestObject (Must Inherite)
Derived Classes()
Derived Classes()

GraphicsObject does not inherit form anyone.
I am working with VB.NET 2005 enterprise edition.

My problem is as such: I need to handle mouse events. I can easly
enough fire them using an outside class and performing a HitTest on the
region. However I would like the indivudal objects to handle there own
events to some extend.
E.G:
If a rectangle is draw on the screen. The rectangle is a derived class
of the shapeObject. When the mouse is clicked inside its bounds the
border should be "Selected." As I said I know how to do this from
another class, but I can't figure out how to link the mouse/ keyboard
events to the base class.

Thank You,
Frank

Mar 27 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a

frank wrote:
Good Morning All,
I am working on a CAD application. At the time of this writing I am
currently working on the GraphicsEngine. The structure is as follows:

GraphicsObject (Base Class, Must Inherit)
ShapeObject (Must Inherit)
Derived Classes()
TestObject (Must Inherite)
Derived Classes()
Derived Classes()

GraphicsObject does not inherit form anyone.
I am working with VB.NET 2005 enterprise edition.

My problem is as such: I need to handle mouse events. I can easly
enough fire them using an outside class and performing a HitTest on the
region. However I would like the indivudal objects to handle there own
events to some extend.
E.G:
If a rectangle is draw on the screen. The rectangle is a derived class
of the shapeObject.
Careful - it might be that you have a Ractangle derived from
ShapeObject, but the thing that's actually *drawn* is just some pixels
on an image.
When the mouse is clicked inside its bounds the
border should be "Selected." As I said I know how to do this from
another class, but I can't figure out how to link the mouse/ keyboard
events to the base class.


Yes, this is the key to the problem. How about this: when you ask the
objects to draw themselves on some Graphics, also ask them to return a
Region representing their presence on the Graphics. Each time you
refresh the drawing, recreate a map (hashtable) of
Region->GraphicsObject. When you receive a mouse click (or whatever),
go through that map and check Region.IsVisible for the point where the
mouse was clicked. If you get a hit, then call (say)
GraphicsObject.OnClick for that object. Make OnClick a MustInherit
method in the base base class.

There might be issues with z-ordering with this method, so I suppose
store a z-order with each region and only OnMouseClick for the latest
drawn GraphicsObject.

Actually wiring up events direct to the objects without any middle
layer looks hard to me, since in the first instance it's always a
PictureBox or whatever that actually receives the Click event.

--
Larry Lard
Replies to group please

Mar 27 '06 #2

P: n/a
Larry,
It's good to "meet" you. Thank you for the advice. I will look into it
this afternoon. I'll let you know how I turn out, and provide some more
information. I realize that there is probally not enough space for all
the infomation needed here.

Best regards,
Frank

Mar 27 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.