Windows form rotation

2020-07-18 09:02发布

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#?

2条回答
在下西门庆
2楼-- · 2020-07-18 09:16

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.

查看更多
ゆ 、 Hurt°
3楼-- · 2020-07-18 09:31

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.

查看更多
登录 后发表回答