Increase/Decrease font size in selection

Posted by: lonewolfthe3rd on 8 September 2017, 2:45 pm EST

  • Posted 8 September 2017, 2:45 pm EST

    Cannot find - how to change a font size (only size!) in short way in "user" selection?

  • Replied 8 September 2017, 2:45 pm EST

    Thank you! Once more: a lot!

    You right. The only way is to declare for init the sheet "base" font with size and then change it. Strange a bit.

    By the way: all new cells in sheets haven't got a font (or I cannot read it from cell). Is it possible to declare for default for new sheet, that all cells will be in pointed font with pointed size?

    And more: when I add new cells into sheet (after sheet's initialization) with declared before font's name and size "by default", these new cells will have declared font and size the same, like in sheet?

    Hope it's clear. English isn't my native language -)

  • Replied 8 September 2017, 2:45 pm EST

    Add my code - mayde it will be helpfull for someone (sorry for vb .net, but interface I preparing in vb):

     Thank you Manpreet Kaur - interesting loops; never thought about it this way<img src="/emoticons/emotion-1.gif" alt="Smile" />

    <span style="color:blue;">Private</span> <span style="color:blue;">Sub</span> tsPlc_Font_Plus_Click(<span style="color:blue;">ByVal</span> sender <span style="color:blue;">As</span> System.<span style="color:#2b91af;">Object</span>, <span style="color:blue;">ByVal</span> e <span style="color:blue;">As</span> System.<span style="color:#2b91af;">EventArgs</span>) <span style="color:blue;">Handles</span> tsPlc_Font_Plus.Click
            <span style="color:blue;">Try</span>
                <span style="color:blue;">Dim</span> cr <span style="color:blue;">As</span> FarPoint.Win.Spread.Model.<span style="color:#2b91af;">CellRange</span> = fpR.Sheets(Tabele).GetSelection(0)
                <span style="color:blue;">Dim</span> r <span style="color:blue;">As</span> <span style="color:blue;">Integer</span> = cr.Row, i <span style="color:blue;">As</span> <span style="color:blue;">Integer</span> = 0
                <span style="color:blue;">While</span> i < cr.RowCount
                    <span style="color:blue;">Dim</span> c <span style="color:blue;">As</span> <span style="color:blue;">Integer</span> = cr.Column, j <span style="color:blue;">As</span> <span style="color:blue;">Integer</span> = 0
                    <span style="color:blue;">While</span> j < cr.ColumnCount
                        <span style="color:blue;">Dim</span> f <span style="color:blue;">As</span> <span style="color:#2b91af;">Font</span> = fpR.Sheets(Tabele).Cells(r, c).Font
                        <span style="color:blue;">If</span> f <span style="color:blue;">IsNot</span> <span style="color:blue;">Nothing</span> <span style="color:blue;">Then</span>
                            <span style="color:blue;">Dim</span> size <span style="color:blue;">As</span> <span style="color:blue;">Single</span> = f.Size
                            size += 1
                            <span style="color:blue;">Dim</span> fnew <span style="color:blue;">As</span> <span style="color:blue;">New</span> <span style="color:#2b91af;">Font</span>(f.FontFamily, size, f.Style)
                            fpR.Sheets(Tabele).Cells(r, c).Font = fnew
                        <span style="color:blue;">Else</span>
                            <span style="color:green;">'MessageBox.Show("No font set")</span>
                        <span style="color:blue;">End</span> <span style="color:blue;">If</span>
                        c += 1
                        j += 1
                    <span style="color:blue;">End</span> <span style="color:blue;">While</span>
                    r += 1
                    i += 1
                <span style="color:blue;">End</span> <span style="color:blue;">While</span>
            <span style="color:blue;">Catch</span> ex <span style="color:blue;">As</span> <span style="color:#2b91af;">Exception</span>
            <span style="color:blue;">End</span> <span style="color:blue;">Try</span>
        <span style="color:blue;">End</span> <span style="color:blue;">Sub</span>
  • Replied 8 September 2017, 2:45 pm EST


    The only way to change the font size for the text in a
    cell is to get the font of the cell in a new font object, get the size
    from this font object, increase or decrease it as required. Again create
    a new font object with all the properties of the old font object and
    the new size. After this you would need to assign the new font object
    back to the cell's Font property. I have created a sample depicting the
    same which I am attaching with this response. Kindly execute the sample,
    make any selection, and click on the "Change selection font" button,
    and it would change the font of the selected cells.

    Please let me know if you have any queries further.


    Manpreet Kaur.
  • Replied 8 September 2017, 2:45 pm EST

            /// <summary>
            /// Increases or decreases the font size of a cell by sizeModifier points as long as the cell has a font.
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void fpSpread1_CellClick(object sender, FarPoint.Win.Spread.CellClickEventArgs e)
                int sizeModifier = 5;

                FarPoint.Win.Spread.Cell cell = ((FarPoint.Win.Spread.FpSpread)sender).ActiveSheet.Cells[e.Row, e.Column];
                if (cell.Font != null)
                    Font font = new Font(cell.Font.FontFamily, cell.Font.Size + sizeModifier);
                    cell.Font = font;
  • Replied 8 September 2017, 2:45 pm EST


    You can set the default font for all the cells in the sheet using the DefaultStyleCollection, which consists of different parts of Spread like ColumnHeader, SheetCorner, DataAreaDefault and many more, you can access any of the parts with this collection and set the font for it in the Form Load event. As soon as you set the font in the DefaultStyleCollection, any new rows or columns you add to Spread, they would inherit the Font from this DefaultStyleCollection and give the same appearance to the row or column but the Font property for each cell would still return null. If you want to get the Font for each cell using the Font property then you would need to set it for each individual cell. Here is the code to accomplish the same:

                                                                   Font f = new Font("Arial",12f,FontStyle.Italic);                                         

                                                                   FarPoint.Win.Spread.DefaultStyleCollection.DataAreaDefault.Font = f;

    I have also created a sample depicting the same, anything you type in any of the cell would be written in the same font and even if you add new row and column by clicking on the button, the cells in them would also have the same default font. Kindly have a look. Please let me know if you have any queries further.


    Manpreet Kaur.

  • Replied 8 September 2017, 2:45 pm EST

    Thanks, good idea!

    Will check in my work tomorrow, when flu finish...

    By the way - about 1,5 year ago was an idea to add something like Excel clone example with ribbons to use by us. Still exists this idea or die?

    Asking, because for me it could be very helpful to get an "ready to implement" Excell like (looks and works) code. Planty of work is, with "clonning" the Excel style working. For me spread is a wonderfull object oriented database for maths, stats and exploration calcs and analysis, but end users "wants Excell style" interface - waste of time a bit...

    Horrible -))

  • Replied 8 September 2017, 2:45 pm EST


    We apologize for the same but the ribbon bar is not available as a separtae dll. Its not distibutable.


    Manpreet Kaur

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels