简体   繁体   English

无论屏幕分辨率如何,都保持按钮在c#中的位置

[英]maintain button's position in c#, no matter the resolution of the screen

i designed a game in c# and finished it... but i tried it on my friend's laptop with different screen size and resolution, all my design was in a total mess!! 我用C#设计了一个游戏,并完成了游戏……但是我在朋友的笔记本电脑上以不同的屏幕尺寸和分辨率尝试了它,我的所有设计都一团糟!

if there is a way to keep everything (panels, picturebox,buttons,labels,...) in their positions despite the size and resolution of screen!?!? 是否有一种方法可以将所有内容(面板,图片框,按钮,标签等)保持在原位,而不管屏幕的大小和分辨率!?!? really need help, my project's deadline is on Monday :( 真的需要帮助,我的项目的截止日期是星期一:(

Use anchors on your controls: 在控件上使用锚点:

替代文字

I assume this is a windows form application? 我认为这是Windows窗体应用程序? If so, you can use docking to maintain positions. 如果是这样,您可以使用停靠来保持位置。 Also, the positions should stay the same anyway unless the form is not a fixed size. 同样,除非表格不是固定大小,否则位置应保持不变。

So use docking or a fixed sized form. 因此,请使用对接或固定大小的表格。

Also, please make sure to specify what type of GUI framework you're using next time. 另外,请确保指定下次使用的GUI框架类型。 My answer is incredibly wrong if you're using something other than windows forms. 如果您使用的不是Windows窗体,则我的答案是非常错误的。

Aside from docking, another option would be to place all of your objects within a panel, and then center it horizontally and vertically on your resize event . 除了停靠之外,另一种选择是将所有对象放置在面板中,然后将其水平或垂直居中于resize event eg 例如

panel1.Left = this.Width/2 + panel1.Width/2;
panel1.Top = this.Height/2 + panel1.Height/2;

This will ensure that your applications static contents are always centered, regardless of resolution. 这将确保您的应用程序静态内容始终居中,而不考虑分辨率。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM