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

    Hello,

    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.

    Thanks,

    Manpreet Kaur.
    2011/09/selectionfont.zip
  • 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 waySmile

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

    Hello,

    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.

    Thanks,

    Manpreet Kaur.


    2011/09/fontonload.zip
  • 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

    Hello,

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

    Thanks,

    Manpreet Kaur

  • Replied 8 September 2017, 2:45 pm EST

            ///
            /// Increases or decreases the font size of a cell by sizeModifier points as long as the cell has a font.
            ///

            ///
            ///
            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;
                }
            }
Need extra support?

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

Learn More

Forum Channels