SshTerminalControl change the size of the font when control resized

0 votes
asked Nov 12, 2012 by pinusmugo (160 points)
edited Nov 13, 2012


I have linux text application with use 80x43 terminal size.

When SshTerminalControl change the size I want to change font size to fit to new control size. (I can't change number of rows and columns).

This behavior has for example putty (option Windows-> When windows is resized change the size of the font).

It is possible using SshTerminalControl ?

If not what can I change in code to achieve this result ?

Best regards, Michael

2 Answers

0 votes
answered Nov 12, 2012 by Lukas Matyska (60,770 points)
edited Nov 12, 2012

Resizing the Font can be done by setting a new value to the TerminalFont property (with font size computed appropriately). Below is a sample class which extends the standard TerminalControl class to show how to do this. Instead of using the TerminalControl class on a Form use the FontResizableTerminalControl class.

public class FontResizableTerminalControl : TerminalControl
    private const int Columns = 80;
    private const int Rows = 24;
    private bool _ready;

    protected override void OnCreateControl()
        _ready = true;

        AutoAdjustTerminalSize = true;

        SetScreenSize(Columns, Rows);

        AutoAdjustTerminalSize = false;


    protected override void OnResize(EventArgs e)

    private void ConsoleFontAdjust()
        if (!_ready)

        float emSize = 6f; // start from 6pt
        float increment = 0.25f;
        int cellMaxWidth = this.ClientSize.Width / Columns;
        int cellMaxHeight = this.ClientSize.Height / Rows;

        int w, h;
            emSize += increment;
            TerminalFont tf = new TerminalFont(this.Font.FontFamily, emSize);
            w = tf.Width;
            h = tf.Height;
        while ((w <= cellMaxWidth) && (h <= cellMaxHeight));

        this.TerminalFont = new TerminalFont(this.Font.FontFamily, (emSize - increment));
0 votes
answered Nov 13, 2012 by pinusmugo (160 points)
edited Nov 13, 2012

Hello Lukas,

Thanks for your response but I'm afraid I still have some problems with this control. I think my question was not clear enough so I would like to explain it further. Problem appears when I resize the window more in weight than height. Adjustment of font is made as long as the weight is in right proportion to the height. The problem appears when weight exceeds this defined proportion and the rest of window is filled with black color. In putty this problem is resolved by using bitmap which stretches the view (also resize font option). I enclose a print screen of stretching view in putty. I understand that it's not easy to add this possibility to this control but maybe you can find a solution for this problem.

(link ) Best regards, Michael.

commented Nov 13, 2012 by Lukas Matyska (60,770 points)
edited Nov 13, 2012

I understand your needs, unfortunately the control is not able to draw font in other than default proportion. Sorry.

But thank you for your comment, we will consider to add this possibility in the future.