开发者

creating resolution independent winform,set resolution for C# winform, get the screen resolution on which the winform is running

I made an application on 1366x768 resolution which is my laptop's current resolution, being a beginner, i din't care about the resolution issues.

When i took that application and executed it on a lower resolution PC , then all was messed up. The form was going somewhere else, most of its part hidden.

So, please help me to how to make my winform resolution independent, or how to get the current screen resolution and set it into my winform so that it changes itself开发者_Python百科 accordingly.


The property

Screen.PrimaryScreen.WorkingArea

is very useful for form sizing and positioning. For example this code:

        this.Width = Screen.PrimaryScreen.WorkingArea.Width/2;
        this.Height = Screen.PrimaryScreen.WorkingArea.Height/2;
        this.Top = (Screen.PrimaryScreen.WorkingArea.Top + Screen.PrimaryScreen.WorkingArea.Height)/4;
        this.Left = (Screen.PrimaryScreen.WorkingArea.Left + Screen.PrimaryScreen.WorkingArea.Width)/4;

(The Screen class is a member of System.Windows.Forms namespace)

will place the form in which it is executed in the middle of the screen and size it to half the screen.

The WorkingArea var is used to exclude stuff like the task bar and other docked items on the desktop when calculating the size of the screen.

Hope this helps.


See here: http://social.msdn.microsoft.com/forums/en-US/vbgeneral/thread/1be40692-80fa-42ba-b316-9fe13a935b4f/ and here: http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/d5f2cd8d-d24d-4574-ba3a-96e22e3d1b56/

General approach is to start with the min resolution you'll be working with. Then you can scale your forms up (using proper docking and anchors).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜