private void _btGraphics_Click(object sender, System.EventArgs e) { // create document C1WordDocument c1Word = new C1WordDocument(); c1Word.Info.Title = "Graphics primitives sample"; _statusBar.Text = "Creating document..."; RectangleF rc = new RectangleF(250, 100, 200, 200); Bitmap image = new Bitmap(GetManifestResource("Word.picture.jpg")); c1Word.DrawImage(image, rc); StringFormat sf = new StringFormat(); sf.Alignment = StringAlignment.Center; sf.LineAlignment = StringAlignment.Center; rc = new RectangleF(250, 100, 150, 20); Font font = new Font("Arial", 14, FontStyle.Italic); c1Word.DrawString(c1Word.Info.Title, font, Color.DeepPink, rc, sf); c1Word.DrawLine(Pens.Green, 200, 190, 400, 190); rc = new RectangleF(150, 150, 190, 80); 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, 150, 80, 80); c1Word.DrawEllipse(Pens.Red, rc); c1Word.FillEllipse(Color.Pink, rc); c1Word.ShapeFillOpacity(70); PointF[] pts = new PointF[4]; pts[0] = new PointF(200, 200); pts[1] = new PointF(250, 300); pts[2] = new PointF(330, 250); pts[3] = new PointF(340, 140); c1Word.DrawPolyline(Pens.BlueViolet, pts); sf = new StringFormat(); sf.Alignment = StringAlignment.Center; sf.LineAlignment = StringAlignment.Far; sf.FormatFlags |= StringFormatFlags.DirectionVertical; rc = new RectangleF(450, 150, 25, 75); font = new Font("Verdana", 12, FontStyle.Bold); c1Word.DrawString("Vertical", font, Color.Black, rc, sf); pts = new PointF[4]; pts[0] = new PointF(372, 174); pts[1] = new PointF(325, 174); pts[2] = new PointF(325, 281); pts[3] = new PointF(269, 281); c1Word.DrawBeziers(Pens.HotPink, pts); _statusBar.Text = "Saving document..."; string fileName = GetFileName(c1Word, "graphics.rtf"); c1Word.Save(fileName); Process.Start(fileName); _statusBar.Text = "Ready."; }
private void _btComplex_Click(object sender, System.EventArgs e) { // create document C1WordDocument c1Word = new C1WordDocument(); c1Word.Info.Title = "Complex sample"; _statusBar.Text = "Creating document..."; // 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); table.BottomBorderStyle = table.LeftBorderStyle = table.RightBorderStyle = table.TopBorderStyle = RtfBorderStyle.Single; table.BottomBorderWidth = table.LeftBorderWidth = table.RightBorderWidth = table.TopBorderWidth = 1; c1Word.Add(table); for (int row = 0; row < rows; row++) { for (int col = 0; col < cols; col++) { var cell = table.Rows[row].Cells[col]; cell.BottomBorderStyle = cell.LeftBorderStyle = cell.RightBorderStyle = cell.TopBorderStyle = RtfBorderStyle.Single; cell.BottomBorderWidth = cell.LeftBorderWidth = cell.RightBorderWidth = cell.TopBorderWidth = 1; RtfParagraph paragraph = new RtfParagraph(); paragraph.Content.Add(new RtfString(string.Format("table cell {0}:{1}.", row, col))); cell.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); _statusBar.Text = "Saving document..."; string fileName = GetFileName(c1Word, "complex.rtf"); c1Word.Save(fileName); Process.Start(fileName); _statusBar.Text = "Ready."; }