|
-
Jul 13th, 2011, 08:33 AM
#1
Thread Starter
Addicted Member
Panel rotation
Dear All,
In my project I have a peculiar requirement for rotating a panel by a standard angel based on mouse drag event. Can anybody please suggest me how a panel can be rotated?
Is it possible with "Rotate Transform" method?
Regards,
Susheelss
-
Jul 13th, 2011, 09:10 AM
#2
Re: Panel rotation
No. It's pretty much impossible to rotate a Panel, or any other default toolbox control.
-
Jul 13th, 2011, 09:20 AM
#3
Re: Panel rotation
It's trivial in WPF though. All that's required is to provide a RotateTransform for either the RenderTransform or LayoutTransform. It's one of the benefits of using a UI framework designed later than the 80s.
This XAML demonstrates how easy it can be:
Code:
<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Slider x:Name="_rotationSlider" Minimum="0" Maximum="359" Value="0" />
<Grid Grid.Row="1" Background="Green">
<Grid.LayoutTransform>
<RotateTransform Angle="{Binding ElementName=_rotationSlider, Path=Value}" />
</Grid.LayoutTransform>
<Grid.Children>
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center">I am in the panel.</TextBlock>
</Grid.Children>
</Grid>
</Grid>
</Window>
Last edited by Sitten Spynne; Jul 13th, 2011 at 09:26 AM.
-
Jul 13th, 2011, 04:21 PM
#4
Re: Panel rotation
If you want to stay with Winforms, you could use the Panel's DrawToBitmap method to take a snapshot of it and rotate that (e.g. on the form or on another panel). Any use? BB
-
Jul 14th, 2011, 03:31 AM
#5
Thread Starter
Addicted Member
Re: Panel rotation
Thanks Mr.minitech, Mr.Sitten Spynne and Mr.boops boops for your valuable reply.
Is it possible to create a rotatable Panel in WPF as a user control and add that control as a new user control on windows form and rotate?
Mr. Boops Boops ,
I have an another picture box inside the Panel which should not rotate and only the panel should rotate. If i use DrawToBitmap method, Then i think even the picturebox will also be shown as rotated. Is there a way to show only the Panel part as rotated and show the picture box static with DrawToBitmap method. Or should i have to again take the Picturebox DrawToBitmap again and paste on the Panel Bitmap?
Regards,
Siddaraju.A.
-
Jul 14th, 2011, 09:31 AM
#6
Re: Panel rotation
 Originally Posted by Susheelss
Is it possible to create a rotatable Panel in WPF as a user control and add that control as a new user control on windows form and rotate?
You can't have your cake and eat it too. There is some sort of WPF control host, but I don't think it's a good idea. Similar to using ActiveX controls in WinForms, there's often odd problems that require goofy workarounds to fix. In particular, I don't think having WinForms content overlap WPF content works very well. Fear of new things is a terminal illness for a programmer's career.
Mr. Boops Boops ,
I have an another picture box inside the Panel which should not rotate and only the panel should rotate. If i use DrawToBitmap method, Then i think even the picturebox will also be shown as rotated. Is there a way to show only the Panel part as rotated and show the picture box static with DrawToBitmap method. Or should i have to again take the Picturebox DrawToBitmap again and paste on the Panel Bitmap?
You can't rotate a container control without rotating its content (Though I suppose in WPF you could apply a counter-rotation to the content so long as everyone's origin agreed...) It sounds more like you want some rectangle that rotates behind the picturebox. It'd be trivial to draw the rectangle at the right location. Perhaps if you could make some images that show what you want to happen someone would be more likely to come up with a solution.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|