如何使用Windows窗体应用程序调整控件宽度 [英] How to adjust the control width using windows forms Application

查看:90
本文介绍了如何使用Windows窗体应用程序调整控件宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我已经使用windows应用程序创建了支持多种语言(本地化)的表单。为实现本地化,我们创建了一个附属组件。



问题是当用户选择能够根据所选语言显示标签文本的语言时。但是控制宽度没有正确调整而是与文本重叠。



请有人告诉我解决方案。



感谢你,

Hi Everyone,

I have created the form with support multiple languages(localization) using windows application.For achieving localization have created a satellite assembly.

The problem is when user selects the language i can able to display the label text according to the selected language.But the control width is not adjusting properly rather it is overlapping the text.

kindly anyone tell me the solution.

Thanking you,

推荐答案

调整标签大小毫无意义。为标签调整大小的适当方法是 myLabel.AutoSize = true ; https://msdn.microsoft.com /en-us/library/system.windows.forms.label.autosize(v=vs.110).aspx [ ^ ]。



它本身并没有解决问题。由于父控件的大小,标签可以完全可见或不可见。 UI设计解决了这些问题,而不是通过调整任何东西。首先,您不应该使用任何手动定位或尺寸。所有控件应按层次对接( DockType 其他),并正确使用正确填充。然后,当您调整窗口或其中一个面板时,您可以实现所有控件的内部内容的自动调整大小。



此外,您应始终为用户提供调整大小的可能性表单及其中的一些部分,通过 Splitter 控件。您永远无法预测某些长词语言(例如德语或匈牙利语)中控件所需的大小。但是,您可以尝试使用以下方法自动计算所需大小并调整表单大小或某些面板的大小: https://msdn.microsoft.com/en-us/library/System.Drawing.Graphics.MeasureString(v = vs.110)的.aspx [ ^ ]。



问题是:那些 System.Drawing.Graphics.MeasureString 方法不精确,因此实际的字符串宽度通常比预测的要大一些。这是一个很大的复杂功能,出现在非等宽字体中,因为它具有如此微妙的效果暗示这个问题在Web上被广泛讨论过,但我仍然不知道完美的解决方案。也许您只需要添加一些额外的空间。



对于某些解决方案和想法,另请参阅此CodeProject文章:绕过Graphics.MeasureString限制 [ ^ ]。



-SA
Adjusting the label size is pointless. The adequate method of sizing for a label is myLabel.AutoSize = true; https://msdn.microsoft.com/en-us/library/system.windows.forms.label.autosize(v=vs.110).aspx[^].

It does not solve the problem itself. The label can be fully visible or not due to the size of the parent controls. Such problems are solved by UI design, not by adjusting anything. First of all, you should never use any manual positioning or sizes. All controls should be hierarchically docked into each other (DockType other then None), with the proper use of the Padding properly. Then you can achieve automatic resizing of inner content of all controls when you resize the window or one of panels.

Also, you should always gives the user the possibility to resize the form, as well as some parts of it, through the Splitter control. You can never predict the size required for a control in some long-word languages, such as German or Hungarian. However, you can try to calculate required size and adjust the form size or the size of some panel automatically, using this methods: https://msdn.microsoft.com/en-us/library/System.Drawing.Graphics.MeasureString(v=vs.110).aspx[^].

The problem is: those System.Drawing.Graphics.MeasureString methods are not precise, so the actual string width is often a bit greater than predicted. This is a big complication which appears in non-monospace fonts due to such delicate effects as hinting The problem was extensively discussed on Web, but I still don't know the perfect solution. Perhaps you need just to add some extra space.

For some solutions and the ideas, see also this CodeProject article: Bypass Graphics.MeasureString limitations[^].

—SA


没有解决方案。您要么削减翻译,要么扩大标签。标签可以通过其宽度更改其宽度属性
There's no "the" solution. You either cut the translation or widen the label. A label can change its width via its Width property.
labelName.Width = newWidthValue;

但没有人会担心实际上有足够的空间让labe成长为新的大小。因此它可以与另一个控件重叠或重叠。

FlowLayoutPanel 类可以提供帮助。或者在按钮上实现横向滚动文本(警告!可以让用户疯狂!)。

But nobody will guaratee that there's actually enough space for the labe to grow to its new size. So it can overlap or be overlapped by another control.
The FlowLayoutPanel class could help. Or implement side-scrolling text on your buttons (Warning! Can drive users crazy!).


我不确定我的解决方案是否有用 - 但是对于类似的问题(机器可视化) / HMI)我创建了特殊的Button和Label。

这些控件可以确保哪个是能够使文本适合控件的最大字体大小。我现在要做的是遍历一组控件(应该具有相同的Fontsize)并查看哪个是常见的最大字体大小。此大小我设置为该组中的所有控件。



此解决方案使得必须自定义应具有此行为的所有控件类型。也许你想这样做 - 在这种情况下,我可以帮助你提供更多信息。
I'm not sure if my Solution is helpful - but for a similiar problem (Visualisation of machines / HMI) I created special Button's and Label's.
These Controls could meassure which is the maximum Fontsize which is able to fit the Text to the Control. What I do now is to iterate through a group of controls (which should have the same Fontsize) and look which is common maximum Fontsize. This Size I set to all Controls in this group.

This Solution makes it necessary to customize all Control-Types which should have this behaviour. Perhaps you want to do it like that - in this case I could help you with further information.


这篇关于如何使用Windows窗体应用程序调整控件宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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