|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Adding event (mouseclick) handlers to GDI+ shapes?I'm trying to add, as you might guess, mouseclick listeners to the shapes I am drawing using the GDI+ commands in a similar sort of way as could be done with the old VB "shapes". Problem is, I'm really not sure of the best way to go about it. I was hoping I could do it directly like the old shape_onclick events, but that doesn't seem to be available for GDIs so maybe I could hack something together using collections of GDI objects and checking to see if mouseclick events occurred within the boundaries of the shapes stored in the collection... I'm not sure how that would work with irregular shapes such as curved lines, among other problems. Any advice you could give on this topic would be gratefully received. New, less-fiddly-to-code directions to follow would also be appreciated. KF Well it sounds to me like you are creating a custom control.
So perhaps you should consider having your control inherit from UserControl (Damn its been too long, is that even the right class???) Then, you will have basic functionality for events; I'm sure OnMouseDown is one of them. Then you customise how your control works by handling the OnPaint event and customising what gets drawn. So say you draw a circle. When you run your onmousedown code, you can write some mathematical code that takes the event arguments x/y mouse click location, and detects if its inside the boundary of your shape. Its a starting point I guess... Yes, that was pretty much what I was thinking I'd have to do. Shame the
Shape object is dead, really. Thanks On Tue, 05 Sep 2006 08:21:22 +0100, Steven Nagy <learndot***@hotmail.com> wrote: Show quoteHide quote > Well it sounds to me like you are creating a custom control. > So perhaps you should consider having your control inherit from > UserControl > (Damn its been too long, is that even the right class???) > Then, you will have basic functionality for events; I'm sure > OnMouseDown is one of them. Then you customise how your control works > by handling the OnPaint event and customising what gets drawn. > > So say you draw a circle. When you run your onmousedown code, you can > write some mathematical code that takes the event arguments x/y mouse > click location, and detects if its inside the boundary of your shape. > > Its a starting point I guess... > If you search theCodeProject.com, you should find some shape controls
made by others. You could probably look at their code to see how they are handling their events. Kristian Frost wrote: Show quoteHide quote > Yes, that was pretty much what I was thinking I'd have to do. Shame the > Shape object is dead, really. > > Thanks > > On Tue, 05 Sep 2006 08:21:22 +0100, Steven Nagy <learndot***@hotmail.com> > wrote: > > > Well it sounds to me like you are creating a custom control. > > So perhaps you should consider having your control inherit from > > UserControl > > (Damn its been too long, is that even the right class???) > > Then, you will have basic functionality for events; I'm sure > > OnMouseDown is one of them. Then you customise how your control works > > by handling the OnPaint event and customising what gets drawn. > > > > So say you draw a circle. When you run your onmousedown code, you can > > write some mathematical code that takes the event arguments x/y mouse > > click location, and detects if its inside the boundary of your shape. > > > > Its a starting point I guess... > > > > > > -- > Using Opera's revolutionary e-mail client: http://www.opera.com/mail/ Its not dead while you still believe...
> Yes, that was pretty much what I was thinking I'd have to do. Shame the Anyway, its going to be the same result in the end. Just a different> Shape object is dead, really. implementation. Create yourself a shapecontrol class that inherits from UserControl and add some key properties for defining the clickable boundaries and the drawing details. I never knew older non-OO versions of VB so I don't know what the exact nature of your old shape objects were. But I bet you can still simulate it. Once you do, let me know... I'd like to see it in action. Little bit of test-code that seems to be doing what I want it to.
Starts by creating a collection of the class written at the bottom of the file, which contains a SolidBrush, Rectangle and a Boolean. MouseDown and MouseUp are handled and their click-coordinates stored, and then checks are made against each shape in the collection in turn to see if the click has fallen within the bounds of any of them. If the click was within the bounds of a shape, it changes colour. If a shape is clicked a second time, a third colour is used, showing that the shape is "off" now, but was "on" at some time in the past. It's all very quick-and-dirty, hurts my eyes after a few minutes, and it only works for Rectangles at the moment, but it does what I need at a level where Button objects just won't cut it. Another question, though: Can I get the Graphics object to not actually refresh until *after* it has added all the Rectangles? At the moment it seems to be wasting a lot of time on refreshing when each component is added, which is fairly unneccessary. All going well so far, thanks for the help. KF On Wed, 06 Sep 2006 00:24:49 +0100, Steven Nagy <learndot***@hotmail.com> wrote: Show quoteHide quote > Its not dead while you still believe... > >> Yes, that was pretty much what I was thinking I'd have to do. Shame the >> Shape object is dead, really. > > Anyway, its going to be the same result in the end. Just a different > implementation. > Create yourself a shapecontrol class that inherits from UserControl and > add some key properties for defining the clickable boundaries and the > drawing details. I never knew older non-OO versions of VB so I don't > know what the exact nature of your old shape objects were. But I bet > you can still simulate it. Once you do, let me know... I'd like to see > it in action. > Note to self: Attach test code.
On Wed, 06 Sep 2006 00:24:49 +0100, Steven Nagy <learndot***@hotmail.com> wrote: Show quoteHide quote > Its not dead while you still believe... > >> Yes, that was pretty much what I was thinking I'd have to do. Shame the >> Shape object is dead, really. > > Anyway, its going to be the same result in the end. Just a different > implementation. > Create yourself a shapecontrol class that inherits from UserControl and > add some key properties for defining the clickable boundaries and the > drawing details. I never knew older non-OO versions of VB so I don't > know what the exact nature of your old shape objects were. But I bet > you can still simulate it. Once you do, let me know... I'd like to see > it in action. >
processor time
Visual Basic.Net & DBF files How can I convert a graphics object to image? Multiple Select listbox and sql stored procedure -Help needed Loop Question list of objects vs Array of objects sound capture (record audio input) in VB.NET???? paramertised select query Why this warning in IDE? Photoshop from vb |
|||||||||||||||||||||||