开发者

How to scale form components with screen resolution in C#?

I create a form with some elements ( a pictureBox, a panel and some labels in it), my application works correctly when I run it in 800*600 resolution. But when I want to run it in another resolution (i.e. 1024*768) the elements go to wrong place. I want to scale(in size and start point) all form elements according to screen resolution. I know that I should use anchor a开发者_开发问答nd Dock, but I cannot. I found some links about use these techniques but it doesn't work well. I use visual studio 2010.

Is there anybody who know a solution of my problem?

Thanks way too much


You are talking about 2 different problems.

  1. UI Scaling / Resolution independence - this is impossible to reach using standard WinForms. Mainly because standard GDI drawing, that WinForms uses never thought about this option. This would allow scale your UI, so that relative sizes and positions would be always same, but it would probably looks differently sized.

  2. Dynamic layout - this technique allows your controls to size and position based on resolution. WinForms has limited options in this, but it can be limitedly achieved using Dock and Anchor properties of all controls. This has nothing to do with scaling or resolution independence.

    Also some 3rd party libraries offer kind of extension of this, to allow more dynamic layouting.

WPF is much more advanced in both UI scaling (because its vector based) and layouting (because it uses double pass layout). But this would require moving to this technology first.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜