Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Selecting objects on a WPF canvas?
Message
De
26/02/2009 14:08:13
 
 
À
26/02/2009 05:21:15
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
Information générale
Forum:
ASP.NET
Catégorie:
Windows Presentation Foundation (WPF)
Divers
Thread ID:
01383557
Message ID:
01384361
Vues:
38
>>>>I think I've done this in the past by creating a region (say a rectangular one based on your four points) then using the .Union() method against each object of interest. If the result is null then the object is not within the region. (This can also be used for selecting muliple objects). It's possible that none of your four points will actually fall within the ellipse even though the initial point is very close to it..
>>>>Haven't access to .NET at the moment so I can't test it.....
>>>>Best,
>>>>Viv
>>>
>>>
>>>I like this idea. Could be helpful as I continue to work with shapes on a canvas.
>>
>>Actually using Geometries rather than regions might be better. This works:
        private void Canvas_MouseDown(object sender, MouseButtonEventArgs e)
>>        {
>>            //Circle around clicked point:
>>            double tolerance = 4;
>>            Point ClickedPoint = e.GetPosition(MainCanvas);
>>            EllipseGeometry eg = new EllipseGeometry();
>>            eg.RadiusX = tolerance; eg.RadiusY = tolerance;
>>            eg.Center = ClickedPoint;
>>
>>            // Geometry of an ellipse object on the canvas:
>>            EllipseGeometry eg2 = new EllipseGeometry();
>>
>>            foreach (Ellipse TargetEllipse in MainCanvas.Children)
>>            {
>>                eg2.RadiusX = TargetEllipse.Width / 2;
>>                eg2.RadiusY = TargetEllipse.Height / 2;
>>                eg2.Center = new Point(
>>                    ((double)TargetEllipse.GetValue(Canvas.LeftProperty)) + TargetEllipse.Width / 2,
>>                    ((double)TargetEllipse.GetValue(Canvas.TopProperty)) + TargetEllipse.Height / 2
>>                    );
>>
>>                //Combine them
>>                CombinedGeometry cg = new CombinedGeometry(GeometryCombineMode.Intersect, eg, eg2);
>>
>>                //Is there an overlap
>>                if (!cg.Bounds.IsEmpty)
>>                {
>>                    // Close enough - do something
>>                }
>>            }
>>        }
Rough code to work with ellipses only - better code would cope with any shape on the Canvas....
>>Best,
>>Viv
>
>
>Viv,
>Recently I noticed that you are heavily involved in WPF 2/3D manipulations. Codes you show are easy once someone like you writes it (how do you say - you make it look easy?). May I come and watch over your shoulder (I can clean the office windows as a pay back:)

I've only got one window so it would probably be a fair exchange <g>

Ah, but if you were looking over my shoulder you'd see the blood, the sweat and the tears along the way :-}
I did the same sort of things years ago working with the Windows API creating ActiveX controls that could be used in VFP. Then I spent about three months doing it with .NET Winforms (where the classes are basically a wrapper to the API - you can see the relationships). Then I junked the whole lot in favour of WPF which makes about 95% of this stuff so much easier. The only problem is you can't fall back on the API for the other 5% !

>Tons of stars from me:)
Thx,Best,
Viv
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform