Results 1 to 6 of 6

Thread: Panel rotation

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2008
    Posts
    204

    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

  2. #2
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    Re: Panel rotation

    No. It's pretty much impossible to rotate a Panel, or any other default toolbox control.

  3. #3
    You don't want to know.
    Join Date
    Aug 2010
    Posts
    4,578

    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.

  4. #4
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    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

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Aug 2008
    Posts
    204

    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.

  6. #6
    You don't want to know.
    Join Date
    Aug 2010
    Posts
    4,578

    Re: Panel rotation

    Quote Originally Posted by Susheelss View Post
    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
  •  



Click Here to Expand Forum to Full Width