Drake
Drake

Reputation: 8392

How to rotate content of a Form?

I would like to rotate the content of a Form (WinForms). Is it possible to implement that behavior in some way?

I already known that with WPF would be easier but the form and the logic are already implemented and in addition I should work with Framework 2.0.

I also known that using video card features that would probably possible, but I need to rotate only one specific form, not all applications running on the target pc.

Upvotes: 1

Views: 3155

Answers (4)

Drake
Drake

Reputation: 8392

At the end I solved this by cloning the form and all the controls that contains (if someone want to take a look the code just comment) and proceed to rotate them one by one.

Private Shared Sub RotateForm180(frm As Form)

    For Each ctrl As Control In frm.Controls
        RotateControl180(ctrl)
    Next

End Sub

Private Shared Sub RotateControl180(ctrl As Control)

    Dim oScreenRect As Rectangle = ctrl.Parent.RectangleToScreen(ctrl.Parent.ClientRectangle)

    ctrl.Location = New Point(oScreenRect.Width - (ctrl.Location.X + ctrl.Width),
                              oScreenRect.Height - (ctrl.Location.Y + ctrl.Height))

    For Each c As Control In ctrl.Controls
        RotateControl180(c)
    Next

End Sub

Form background can also by rotated.

_BackgroundImage.RotateFlip(RotateFlipType.Rotate180FlipNone)

Upvotes: -1

Sogger
Sogger

Reputation: 16142

Can you create a wpf window with a WindowsFormHost holding your content and then apply a rotation transform to it?

Upvotes: 0

Anton Semenov
Anton Semenov

Reputation: 6347

Basicly You cant do this. There are two possible way to solve the problem

  1. Find third party controls, which can be rotated
  2. Rewrite all controls. You should ovveride paint method of ALL controls you want to rotate, so they will owner drawed.

Upvotes: 0

Coincoin
Coincoin

Reputation: 28616

If you draw the content by yourself using OnPaint, you can use Graphics.Transform and feed it a rotation matrix or use Graphics.RotateTransform(float angle).

Be aware that this will not be perfect though. Some things might not rotate as expected such as text and images.

Upvotes: 3

Related Questions