Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
1.60/5 (2 votes)
See more:
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,
Posted
Comments
Philippe Mori 21-Jul-15 13:02pm    
You should usually avoid customizing layout for a specific language but design form with enough room for larger labels. Try also to use autosizing, docking and anchors as appropriate.

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
 
Share this answer
 
v2
There's no "the" solution. You either cut the translation or widen the label. A label can change its width via its Width property.
C#
labelName.Width = newWidthValue;
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!).
 
Share this answer
 
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.
 
Share this answer
 
Comments
Bitto kumar 22-Jul-15 2:49am    
Hi Ralf,Thanks for your reply.i am not sure that size of the label because depending on selected language it has to display the text from resource file.And more over a form contains more than 100 controls.
Ralf Meier 22-Jul-15 3:16am    
In my Suggestion the Size of the Controls will allways be the same.
You don't need to change the Control-Size - I change the Font-Size (and perhaps I also change the Text-Wordwrapping)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900