Click here to Skip to main content
15,314,594 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, I have multiple shapes on canvas. I need to generate a bounding rectangle around all the selected shapes without altering their existing positions. And I should be able resize and rotate them as well. When i resize the whole group the scale should apply to all the shapes inside. Right now Im able to select multiple shapes and able to resize them at a time as well, but i dont have common bounding rectangle for those selected shapes.
Im a beginner for WPF.Kindly post any ideas regarding the issue. Thanks in advance.

Revanth M.
Posted
Comments
hzawary 22-Oct-11 9:48am
   
Are you want to have a selection tool like other paint software?
Revanthkumar M 23-Oct-11 23:38pm
   
thankyou hzawary for considering. I need have a selection for that bounding box. Not the box I get when im dragging the mouse clicking left mouse, but a permanent box around the selected shapes.
BillWoodruff 22-Oct-11 21:37pm
   
Since I am not a use of WPF, I'll include this as a comment, not a solution, but can't you easily iterate (foreach ?) over the collection of selected shapes, and just calculate min and max x,y co-ordinates which will easily give you the bounding-box ?
Revanthkumar M 23-Oct-11 23:40pm
   
Thankyou Bill for considering,I can do tht but i cant arrange a box around those shapes unless I keep them in another canvas or panel,which will not give me any resizing or rotation.

Please see if this suits your solution:

<Border
BorderThickness="2"
BorderBrush="Black">
<Canvas>
Your shapes
</Canvas>
</Border>

Use ScaleTransform on your border.

(If you intend to use ScaleTransform + LinearTransform, wrap them in TransformGroup)

Example:
<Border BorderBrush="Black" BorderThickness="2" Height="200" Width="200">
<Canvas>
<Ellipse Width="150" Height="150" StrokeThickness="2" Stroke="Black"/>
</Canvas>
<Border.RenderTransform>
<ScaleTransform ScaleX="0.5" ScaleY="0.5"/>
</Border.RenderTransform>
</Border>

Let me know if you need any more clarifications, will be happy to help!

Mark as answer if this solves! :)

Thanks!
   
v3
Comments
Revanthkumar M 27-Oct-11 3:05am
   
Thank you very much Jyothikarthik for considering. But How can I be able to resize the bounding rectangle without any handlers???I want to implement something similar to grouping in MS PowerPoint. Atleast I should be able to move the group around with bounding rectangle. Thanks again and and kindly look into the problem again.
hzawary 1-Nov-11 10:14am
   
Not solved your problem yet?!!!
Can you send program in complete and explain more about it?
Also, you can see this subject "Grouping line and Circle in object c# drawing" in this link "http://www.codeproject.com/Questions/261942/Grouping-line-and-Circle-in-object-csharp-drawing"
Thanks guys for your replies..... Anyways I got the solution for my problem. I got code for grouping and rotation and resize separately. I did some work and able to mix them both into one. And trying to make the code more fool proof. Here are the links that helped me. Thanks once again.


WPF Diagram Designer: Part 1[^]


WPF Diagram Designer - Part 4[^]
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900