开发者

Resizing the form when the Language changes

开发者 https://www.devze.com 2023-03-14 20:25 出处:网络
C# WinForms: Imagine there are a bunch of controls inside the red and yellow panels.Actually they do not need to be panels. Whatever you suggest is Ok.

C# WinForms: Imagine there are a bunch of controls inside the red and yellow panels. Actually they do not need to be panels. Whatever you suggest is Ok. Functionality Required: when it is English language resizing is Ok because the form just looks like what I had designed in designer. when the language changes there the issue appears because the label gets a very longer text in translated mode and it just does not fit it the yellow are. So: (1) I want some UI design idea that when the label needs more room, it auto resizes and the yellow area r开发者_如何学JAVAesizes and pushes the Red area to the right and also the form will resize of course to show everything. 2) I want the Red area to grow if I resize the form so I can do this by Anchoring the red area to the right, fine...BUT I do Not want the Yellow area to resize if I resize the Form. I only want it resize when the contents inside it need more room. 3) I may be wrong be I used a TableLayout with two columns for red and yellow areas and put the columns on AutoSize mode but it did not fix the issue....

what do you suggest?

Resizing the form when the Language changes


The best way to do this is to make a class that inherits the System.Forms.Controls.Button or Label class. Override the TextChanged event, then in your Paint function, use MeasureFont to measure the size of the text and change the size of the button accodingly. So something like this:

public class MyButton : Button 
{
    protected override void OnPaint(PaintEventArgs pe)
    {
        Graphics g = pe.Graphics;

        SizeF stringSize = g.MeasureFont(this.Text, this.Font);

        this.Resize(SizeF.Width + 10, SizeF.Height + 10);
     }
}

Something along those lines. I have not tested this.

0

精彩评论

暂无评论...
验证码 换一张
取 消