如何使控件自动调整大小,同时屏幕和屏幕的背景图像也在C#中调整大小? [英] how to make the controls are automatically resized, while the screen and the background image of the screen is also resized in C#?

查看:100
本文介绍了如何使控件自动调整大小,同时屏幕和屏幕的背景图像也在C#中调整大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I'm making a Windows Form that has a background image using Image Stretch property to be automatically resized while the screen is resized, but what I'm needing is a control like a button for example and also the text of the button using the Fill Dock Property, will also be automatically resized while the screen and the background image of the screen is resized.
The result that I need is similar to the program that can be seen by downloading <a href="http://www.mediafire.com/download/h8z52if6pswe90b/TM-L500A.rar">here</a>

Note that in this example the application the buttons and text buttons are also resized automatically according to the screen and the background image of the screen is resized.
How can I do this in C#?

Many thanks in advance.
Kind regards,

推荐答案

大约5天前,在Windows窗体应用程序的上下文中,有一个类似的问题,您可能会在OP中找到我的对话框(在评论中)和我发布的( a)解决方案有用:[ ^ ]。



但是,我建议你不要尝试动态重新调整大小和Win-Controls的重新定位,除非绝对必要:imho,太多的工作太少回报,并且很有可能任意重新调整大小会导致UI看起来很糟糕。
About 5 days ago, in the context of a Windows Form Application, there was a similar question, and you might find my dialog (in the comments) with the OP, and my posted (outline of a) "solution" useful: [^].

But, I advise you against attempting dynamic re-sizing and re-positioning of Win Form Controls unless absolutely necessary: imho, too much work for too little a return, and a good chance that arbitrary re-sizing will result in a UI that looks terrible.


请看我过去的答案:

屏幕分辨率时Zom Out出现故障在变化 [ ^ ],

如何停靠按钮,以便它可以使用表格进行调整 [ ^ ]。





回答有关WPF的问题。在WPF中,一切都与 System.Windows.Forms 中的几乎相同,但它有一个额外的功能,可以让你自动重新缩放所有内容,图像,矢量或像素图形,任何控件,一切。这是装饰器 System.Windows.Controls.Viewbox

http://msdn.microsoft.com/en-us/library/system.windows。 controls.viewbox%28v = vs.110%29.aspx [ ^ ]。



正如我已经提到的,你可能需要照顾图像的宽高比。这是通过属性 System.Windows.Controls.Viewbox.Streatch 完成的:

http://msdn.microsoft.com/en-us/library/system.windows.controls.viewbox.stretch.aspx [ ^ ],

http:// msdn .microsoft.com / zh-cn / library / system.windows.media.stretch.aspx [ ^ ]。



在这里你可以找到一个明确的解释: http://stackoverflow.com /问题/ 288954 /怎么办-I-保持纵横比上可伸缩的,可滚动康特nt-in-wpf [ ^ ]。



-SA
Please see my past answers:
Zom Out malfunctions when Screen resolution changes[^],
how to dock button so that it can adjust with the form[^].


Answering the question about WPF. In WPF, everything is the pretty much the same as in System.Windows.Forms, but it has one additional feature which would allow you to automatically re-scale absolutely everything, images, vector or pixel graphics, any controls, everything. This is the decorator System.Windows.Controls.Viewbox:
http://msdn.microsoft.com/en-us/library/system.windows.controls.viewbox%28v=vs.110%29.aspx[^].

As I already mentioned, you probably need to take care of the aspect ratio of an image. This is done via the property System.Windows.Controls.Viewbox.Streatch:
http://msdn.microsoft.com/en-us/library/system.windows.controls.viewbox.stretch.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.media.stretch.aspx[^].

Here you can find a clear explanation of it: http://stackoverflow.com/questions/288954/how-do-i-keep-aspect-ratio-on-scalable-scrollable-content-in-wpf[^].

—SA


这篇关于如何使控件自动调整大小,同时屏幕和屏幕的背景图像也在C#中调整大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆