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
Printable View
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
No. It's pretty much impossible to rotate a Panel, or any other default toolbox control.
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>
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
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.
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.
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.Quote:
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?