Reputation: 1193
I have a Windows Forms application which contains a couple of labels, a button and a combobox all wrapper inside a Panel.
this.pnlSuboptions.Controls.Add(this.label1);
this.pnlSuboptions.Controls.Add(this.cboPtSize);
this.pnlSuboptions.Controls.Add(this.label2);
this.pnlSuboptions.Controls.Add(this.btnSelect);
I facing an issue with my labels when I try loading localized strings for my labels. The localized strings for some languages are larger than the English strings. In such cases, a part of the label gets hidden under the combo box or the button.
I want the label to increase in size towards the left instead of right. I've set my labels' AutoSize property to true and also played around with the Anchor property but nothing seems to work.
I found an SO link which contains a solution to this problem when the label text changes but I'm sure how I can apply this in my scenario where the label is read only once during the form load.
Any suggestions?
Upvotes: 4
Views: 21851
Reputation: 1304
You could put them into a TableLayoutPanel with 2 columns and two rows. Each label goes in left side of each row and both combo box/buttons goes in the others cells (right side of each row).
Then you must dock both elements (Dock Fill) and set the columns to AutoSize. (As you can see in the image)
You also may want to dock the TablePanelLayout to your common panel.
As you can see in the image below, both TablePanelLayout have the same components. But in the secoend I just changed the label3's text.
Hope it helps. (Also sorry for my bad english, it isn't my native language. Please feel free to correct any wrong spelling, thanks!)
Upvotes: 5
Reputation: 1249
First suggestion from me would be:
Second suggestion, you can use the GDI+ to determine the size of the text and then resize the label accordingly See http://msdn.microsoft.com/en-us/library/6xe5hazb(v=vs.110).aspx
Graphics gfx = this.label1.CreateGraphics(); // I think its called that, cant remember :)
Font stringFont = new Font("Arial", 16);
// Measure string.
SizeF stringSize = new SizeF();
stringSize = gfx.MeasureString(this.label1.Text, stringFont);
this.label1.Size = new Size((int)stringSize.Width, (int)stringSize.Height);
Oh yeah I almost forgot. Make sure that you're panel is not the cause of the clipping. I mean, check if the panel is large enough for the labels to fit :-)
Hope this helps!
Best regards, Zerratar
Upvotes: 5