add events to a system.drawing.rectangle class

L

Laoballer

I'm trying to draw a rectangle onto a windows form that has events
associated with the rectangle. For example, once the rectangle is
drawn on the form if I hover over it it would display it's size as a
tooltip, or maybe when I click on the rectangle it's border changes
color indicating that it's been selected. Any clues or ideas as to
how I would implement this? I'm fairly new to C# and windows
programming. Currently I'm able to draw the rectangles.

Thanks in advance.
 
P

Peter Duniho

Laoballer said:
I'm trying to draw a rectangle onto a windows form that has events
associated with the rectangle. For example, once the rectangle is
drawn on the form if I hover over it it would display it's size as a
tooltip, or maybe when I click on the rectangle it's border changes
color indicating that it's been selected. Any clues or ideas as to
how I would implement this? I'm fairly new to C# and windows
programming. Currently I'm able to draw the rectangles.

You'll need to handle the mouse events to detect the situation. In the
Form sub-class, you can override OnMouseMove(), OnMouseDown(), etc.

The actual event can be implemented using the "event" keyword in C#.
Clients can subscribe to event and respond appropriately when you raise
them.

If you only want to provide a response internally to your Form sub-class
(e.g. just change the way the Form graphics are drawn), then you don't
really need an event. Just call appropriate methods within the Form
class from your mouse event handling code.

Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top