0 votes
by (160 points)
edited

Hello,

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
by (70.2k points)
edited

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;

        Parent.SuspendLayout();
        AutoAdjustTerminalSize = true;

        SetScreenSize(Columns, Rows);

        AutoAdjustTerminalSize = false;
        Parent.ResumeLayout();

        base.OnCreateControl();
    }

    protected override void OnResize(EventArgs e)
    {
        ConsoleFontAdjust();
        base.OnResize(e);
    }

    private void ConsoleFontAdjust()
    {
        if (!_ready)
            return;

        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;
        do
        {
            emSize += increment;
            TerminalFont tf = new TerminalFont(this.Font.FontFamily, emSize);
            w = tf.Width;
            h = tf.Height;
            tf.Dispose();
        }
        while ((w <= cellMaxWidth) && (h <= cellMaxHeight));

        this.TerminalFont = new TerminalFont(this.Font.FontFamily, (emSize - increment));
    }
}
0 votes
by (160 points)
edited

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 http://s000.tinyupload.com/?file_id=12766351172312921624 ) Best regards, Michael.

by (70.2k points)
edited

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.

...