tags:

views:

533

answers:

2

in WinForms I can use Control.Scale to scale control larger. when I do that, all child controls are repositioned and scaled correctly, but font size remains the same.

is there an easy way to force font to scale up/down as well? or is the only way for me to manually update font for all controls when control is being scaled?

background: I'm working on a program in which I need to support zoom in/out to make labels, textboxs, etc. more readable for users with poor eyesight.

+1  A: 

Do it the other way around. Change the font size, the controls will automatically scale to accommodate the larger font. For example:

  public partial class Form1 : Form {
    float mDesignSize;
    int mIncrement;
    public Form1() {
      InitializeComponent();
      mDesignSize = this.Font.SizeInPoints;
    }
    private void adjustFont() {
      float size = mDesignSize * (1 + mIncrement / 7f);
      this.Font = new Font(this.Font.FontFamily, size);
    }
    private void btnIncreaseFontSize_Click(object sender, EventArgs e) {
      mIncrement += 1;
      adjustFont();
    }
    private void btnDecreateFontSize_Click(object sender, EventArgs e) {
      mIncrement -= 1;
      adjustFont();
    }
  }
Hans Passant
this won't scale controls location. I can use table layout, but it has it's own drawbacks.
Ornus
+1  A: 

I couldn't find solution so I ended up scaling font by hand.

I'm using Krypton Toolkit *highly recommended, great controls library) which supports themes. I simply used reflection to find all font properties and scale them up.

Ornus