Quantcast
Viewing all articles
Browse latest Browse all 38

Spread Windows Forms and Page Breaks

Some applications allow you to view page breaks for printing. You can use code to add visual indicators for page breaks in Spread for Windows Forms.

There are several ways to add visible page breaks in Spread Windows Forms. You can add a border to the row or column, a backcolor to the header, or an image to the header.

This example adds visual indicators for the row page breaks.

Use the following steps to create this example:

  1. Create a form.
  2. Add Spread and three buttons to the form.
  3. Add a list box to the form.
  4. Add the following code.

C#

private void Printing1_Load(object sender, EventArgs e)
        {
            fpSpread1.Open("C:\\Program Files (x86)\\GrapeCity\\Spread Studio 9\\Common\\CostOfGoodSold.xml");
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int[] i;
            i = fpSpread1.GetRowPageBreaks(0);
            foreach (object o in i)
            {
                listBox1.Items.Add(o);
                // Set a border for the row
                fpSpread1.Sheets[0].Cells[(int)o, 0, (int)o, fpSpread1.Sheets[0].Columns.Count - 1].Border = new FarPoint.Win.LineBorder(Color.Red, 2, false, true, false, false);
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            int[] i;
            i = fpSpread1.GetRowPageBreaks(0);
            foreach (object o in i)
            {
                listBox1.Items.Add(o);
                // Set the color for a header cell
                fpSpread1.Sheets[0].RowHeader.Cells[(int)o, 0].BackColor = Color.Red;
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            FarPoint.Win.Spread.CellType.ImageCellType imagecell = new FarPoint.Win.Spread.CellType.ImageCellType();
            System.Drawing.Image image = System.Drawing.Image.FromFile("C:\\Program Files (x86)\\GrapeCity\\Spread Studio 9\\Common\\SD.ico");

            int[] i;
            i = fpSpread1.GetRowPageBreaks(0);
            foreach (object o in i)
            {
                listBox1.Items.Add(o);
                // Add an image to the header cell
                fpSpread1.Sheets[0].RowHeader.Cells[(int)o, 0].CellType = imagecell;
                fpSpread1.Sheets[0].RowHeader.Cells[(int)o, 0].Value = image;
            }
        }

VB

Private Sub Printing1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        FpSpread1.Open("C:\Program Files (x86)\GrapeCity\Spread Studio 9\Common\CostOfGoodSold.xml")
    End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim i() As Integer        
        Dim o As Object
        i = FpSpread1.GetRowPageBreaks(0)
        For Each o In i
            ListBox1.Items.Add(o)         
            ‘ Set a border for the row   
            FpSpread1.Sheets(0).Cells(CInt(o), 0, CInt(o), FpSpread1.Sheets(0).Columns.Count - 1).Border = New FarPoint.Win.LineBorder(Color.Red, 2, False, True, False, False)
        Next
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Dim i() As Integer        
        Dim o As Object
        i = FpSpread1.GetRowPageBreaks(0)
        For Each o In i
            ListBox1.Items.Add(o)
            ‘ Set a color for the header cell
            FpSpread1.Sheets(0).RowHeader.Cells(CInt(o), 0).BackColor = Color.Red
        Next
    End Sub

    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
        Dim imagecell As New FarPoint.Win.Spread.CellType.ImageCellType()
        Dim image As System.Drawing.Image
        image = System.Drawing.Image.FromFile("C:\Program Files (x86)\GrapeCity\Spread Studio 9\Common\SD.ico")

        Dim i() As Integer        
        Dim o As Object
        i = FpSpread1.GetRowPageBreaks(0)
        For Each o In i
            ListBox1.Items.Add(o)
            ‘ Add an image to the header cell
            FpSpread1.Sheets(0).RowHeader.Cells(CInt(o), 0).CellType = imagecell
            FpSpread1.Sheets(0).RowHeader.Cells(CInt(o), 0).Value = image
        Next
    End Sub

You can use the GetColumnPageBreaks method to get column page breaks.

Use the following steps to create an example that gets the column page breaks and sets a border, header color, or adds an image to the header:

  1. Create a form.
  2. Add Spread and three buttons to the form.
  3. Add a list box to the form.
  4. Add the following code.

C#

private void Printing1_Load(object sender, EventArgs e)
        {
            fpSpread1.Open("C:\\Program Files (x86)\\GrapeCity\\Spread Studio 9\\Common\\CostOfGoodSold.xml");   
        }       

        private void button1_Click(object sender, EventArgs e)
        {
            int[] i;
            i = fpSpread1.GetColumnPageBreaks(0);
            foreach (object o in i)
            {
                listBox1.Items.Add(o);
                fpSpread1.Sheets[0].Cells[0, (int)o, fpSpread1.Sheets[0].Rows.Count - 1, (int)o].Border = new FarPoint.Win.LineBorder(Color.Red, 2, true, false, false, false);               
            }
        }

private void button2_Click(object sender, EventArgs e)
        {
            int[] i;
            i = fpSpread1.GetColumnPageBreaks(0);
            foreach (object o in i)
            {
                listBox1.Items.Add(o);
                fpSpread1.Sheets[0].ColumnHeader.Cells[0, (int)o].BackColor = Color.Red;
            }
        }

private void button3_Click(object sender, EventArgs e)
        {
            FarPoint.Win.Spread.CellType.ImageCellType imagecell = new FarPoint.Win.Spread.CellType.ImageCellType();
            System.Drawing.Image image = System.Drawing.Image.FromFile("C:\\Program Files (x86)\\GrapeCity\\Spread Studio 9\\Common\\SD.ico");

            int[] i;
            i = fpSpread1.GetColumnPageBreaks(0);
            foreach (object o in i)
            {
                listBox1.Items.Add(o);
                fpSpread1.Sheets[0].ColumnHeader.Cells[0,(int)o].CellType = imagecell;
                fpSpread1.Sheets[0].ColumnHeader.Cells[0,(int)o].Value = image;
            }
        }

VB

Private Sub Printing1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        FpSpread1.Open("C:\Program Files (x86)\GrapeCity\Spread Studio 9\Common\CostOfGoodSold.xml")
End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim i() As Integer
        Dim o As Object
        i = FpSpread1.GetColumnPageBreaks(0)
        For Each o In i
            ListBox1.Items.Add(o)
            FpSpread1.Sheets(0).Cells(0, CInt(o), FpSpread1.Sheets(0).Rows.Count - 1, CInt(o)).Border = New FarPoint.Win.LineBorder(Color.Red, 2, True, False, False, False)
        Next
End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Dim i() As Integer
        Dim o As Object
        i = FpSpread1.GetColumnPageBreaks(0)
        For Each o In i
            ListBox1.Items.Add(o)
            FpSpread1.Sheets(0).ColumnHeader.Cells(0, CInt(o)).BackColor = Color.Red
        Next
End Sub

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
        Dim imagecell As New FarPoint.Win.Spread.CellType.ImageCellType()
        Dim image As System.Drawing.Image
        image = System.Drawing.Image.FromFile("C:\Program Files (x86)\GrapeCity\Spread Studio 9\Common\SD.ico")

        Dim i() As Integer
        Dim o As Object
        i = FpSpread1.GetColumnPageBreaks(0)
        For Each o In i
            ListBox1.Items.Add(o)
            FpSpread1.Sheets(0).ColumnHeader.Cells(0, CInt(o)).CellType = imagecell
            FpSpread1.Sheets(0).ColumnHeader.Cells(0, CInt(o)).Value = image
        Next
End Sub

Viewing all articles
Browse latest Browse all 38

Trending Articles