ComponentOne Word for WinForms
Working with Word for WinForms / Advanced Level Working / Adding Complex Text
In This Topic
    Adding Complex Text
    In This Topic

    Adding text, images, tables and graphics to your document makes it more interactive. Using Word component, you can easily add title, images, tables, and graphics to your word document. Till now, you have seen how to add simple text to your document. But your document is actually a composite set of text, images, pictures, graphics etc which actually constitutes a complex text. The code given below adds title, images, tables, and graphics to your word document - all in one code:

    ' add title
    C1Word.AddParagraph(C1Word.Info.Title, New Font("Tahoma", 24, FontStyle.Italic), Color.BlueViolet)
    
    ' add image
    C1Word.AddParagraph("picture:", New Font("Courier New", 9, FontStyle.Regular), Color.Black)
    Dim img As New Bitmap(GetManifestResource("picture.jpg"))
    C1Word.AddPicture(img, RtfHorizontalAlignment.Center)
    
    ' add table
    C1Word.LineBreak()
    Dim rows As Integer = 7
    Dim cols As Integer = 2
    Dim table As New RtfTable(rows, cols)
    C1Word.Add(table)
    For row As Integer = 0 To rows - 1
            For col As Integer = 0 To cols - 1
                    Dim paragraph As New RtfParagraph()
                    paragraph.Content.Add(New RtfString(String.Format("table cell {0}:{1}.", row, col)))
                    table.Rows(row).Cells(col).Content.Add(paragraph)
            Next
    Next
    
    ' add graphics
    C1Word.LineBreak()
    C1Word.DrawLine(Pens.Green, 200, 90, 400, 90)
    
    Dim rc = New RectangleF(150, 170, 90, 40)
    Using pen As New Pen(Brushes.Blue, 5F)
            C1Word.DrawRectangle(pen, rc)
    End Using
    C1Word.FillRectangle(Color.Gold, rc)
    C1Word.ShapeFillOpacity(50)
    C1Word.ShapeRotation(25)
    
    rc = New RectangleF(300, 120, 80, 80)
    C1Word.DrawEllipse(Pens.Red, rc)
    C1Word.FillEllipse(Color.Pink, rc)
    C1Word.ShapeFillOpacity(70)
                                    
    
                // add title
                C1Word.AddParagraph(C1Word.Info.Title, new Font("Tahoma", 24, FontStyle.Italic), Color.BlueViolet);
    
                // add image
                C1Word.AddParagraph("picture:", new Font("Courier New", 9, FontStyle.Regular), Color.Black);
                Bitmap img = new Bitmap(GetManifestResource("picture.jpg"));
                C1Word.AddPicture(img, RtfHorizontalAlignment.Center);
    
                // add table
                C1Word.LineBreak();
                int rows = 7;
                int cols = 2;
                RtfTable table = new RtfTable(rows, cols);
                C1Word.Add(table);
                for (int row = 0; row < rows; row++)
                {
                    for (int col = 0; col < cols; col++)
                    {
                        RtfParagraph paragraph = new RtfParagraph();
                        paragraph.Content.Add(new RtfString(string.Format("table cell {0}:{1}.", row, col)));
                        table.Rows[row].Cells[col].Content.Add(paragraph);
                    }
                }
    
                // add graphics
                C1Word.LineBreak();
                C1Word.DrawLine(Pens.Green, 200, 90, 400, 90);
    
                var rc = new RectangleF(150, 170, 90, 40);
                using (Pen pen = new Pen(Brushes.Blue, 5.0f))
                {
                    C1Word.DrawRectangle(pen, rc);
                }
                C1Word.FillRectangle(Color.Gold, rc);
                C1Word.ShapeFillOpacity(50);
                C1Word.ShapeRotation(25);
    
                rc = new RectangleF(300, 120, 80, 80);
                C1Word.DrawEllipse(Pens.Red, rc);
                C1Word.FillEllipse(Color.Pink, rc);
                C1Word.ShapeFillOpacity(70);