views:

458

answers:

3

When you create a form in .Net it appears as a dialog box in a portrait layout.

No one normally likes to read sideways, or upside down, but I have a very valid reason to rotate the form.

Anyone knows how to do it on Windows Vista with C#?

+3  A: 

Does it have to be in WinForms? This is very easy to do in WPF, using rotation transforms. Unfortunately, the WindowsFormsHost integration with WPF does not allow rotation transforms.

EDIT

I understand, now, that the form in question is out of the control of the poster. Writing the control in WPF won't fix the problem.

Brian Genisio
WPF will rotate the entire form, including the title bar and the windows controls and so on?
MusiGenesis
thanks a lot. To make things clearer, I have a third party program that I start from a WPF project as a new process. I have no control over the way the third party program was designed. I interact with it through mouse and kbrd simulations. But I need to rotate the whole window. Is it possible to run the third party program from within a WPF window. Is it then possible to use animation (i.e. rotation, translation, etc)? Thanks again for your response.
+1  A: 

Maybe this one might help you, i had a similar question

Chocol8
No, that only works on Windows Mobile (it uses Microsoft.WindowsCE.Forms, which won't work in regular Windows). I should know - I answered that question . :)
MusiGenesis
+1 Once again thanks!
Chocol8
A: 

This would be a bit of extra work, but if you mainly just need the contents of the form to be rotated (and not the entire window including title bar, window controls etc., which I've never seen before), you could instead make an entirely owner-drawn usercontrol that was rotated 90 degrees, and drop it on an ordinary form. You wouldn't even have to adjust your drawing of everything, since you could do a RotateTransform on your Graphics object and then draw everything normally.

Or if you need the entire form rotated, you could make the form borderless and then do basically the same thing, drawing the title bar and windows controls yourself also.

Update: here's a link to an MSDN article that shows how to rotate the entire screen in C#:

http://msdn.microsoft.com/en-us/library/ms812499.aspx

This is for regular Windows (not Windows Mobile), so it should work for your porpoises, although it will rotate all of Windows and not just your application's form. Depending on how fast this works and your overall needs, you could rotate the screen 90 degrees when your application gets the focus, and then rotate it back to normal when your app loses focus.

Update 2: I just reread your question and comments. You're talking about rotating the window of a separate application in a separate process, so WPF will definitely not help you here. The MSDN link might be what you need. In your application, you would rotate the screen 90 degrees, then start the other application in a separate process. This would work best if you could force the separate application's window to be maximized, which you can do by P/Invoking the FindWindow and SendMessage APIs (you could also make the window always on top, which would put your computer into a sort of kiosk mode for this application). There's a version of the Process code that basically makes starting another application a blocking call, which means your app will wait for the shelled application to close before resuming. Once the app closes, you can put the screen back to its normal orientation.

MusiGenesis
thanks... As in my comment above it is a third party program that I can not make borderless. It would be greate if I can rotate the whole window. I tried System.Drawing.Graphics, but it seems not supporting a rotation/ orientation. Thanks again.