using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

// Open the Add References dialog, open the Assemblies branch,
// select the the Extensions tab, and check:
//      Microsoft.Office.Interop.Word
using Word = Microsoft.Office.Interop.Word;

namespace CreateWordDoc
{
    public partial class frm19CreateWordDoc : Form
    {
        public frm19CreateWordDoc()
        {
            InitializeComponent();
        }

        // Make a Word document.
        private void makeButton_Click(object sender, EventArgs e)
        {
            // Get the Word application object.
            Word.Application word = new Word.Application();

            // Uncomment to make Word visible.
            //word.Visible = true;

            // Create the Word document.
            Word.Document doc = word.Documents.Add();

            // Create a header paragraph.
            Word.Paragraph para = doc.Paragraphs.Add();
            para.Range.Text = "Chrysanthemum Curve";
            object style = "Heading 1";
            para.Range.set_Style(ref style);
            para.Range.InsertParagraphAfter();

            // Add more text.
            para.Range.Text = "To make a chrysanthemum curve, use the following " +
                "parametric equations as t goes from 0 to 21 * π to generate " +
                "points and then connect them.";
            para.Range.InsertParagraphAfter();

            // Save the current font and start using Courier New.
            string oldFont = para.Range.Font.Name;
            float oldSize = para.Range.Font.Size;
            para.Range.Font.Name = "Courier New";
            para.Range.Font.Size -= 2;

            // Add the equations.
            para.Range.Text =
                "  r = 5 * (1 + Sin(11 * t / 5)) -\n" +
                "      4 * Sin(17 * t / 3) ^ 4 *\n" +
                "      Sin(2 * Cos(3 * t) - 28 * t) ^ 8\n" +
                "  x = r * Cos(t)\n" +
                "  y = r * Sin(t)";

            // Start a new paragraph and then switch back to the original font.
            para.Range.InsertParagraphAfter();
            para.Range.Font.Name = oldFont;
            para.Range.Font.Size = oldSize;

            // Add a little more text.
            para.Range.Text = "That's all for this example.";
            para.Range.InsertParagraphAfter();

            // Save the document.
            object filename = Application.StartupPath + "\\test.docx";
            doc.SaveAs(ref filename);

            // Close.
            doc.Close();
            word.Quit();

            MessageBox.Show("Done");
        }


        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.makeButton = new System.Windows.Forms.Button();
            this.SuspendLayout();
            // 
            // makeButton
            // 
            this.makeButton.Location = new System.Drawing.Point(105, 19);
            this.makeButton.Name = "makeButton";
            this.makeButton.Size = new System.Drawing.Size(75, 23);
            this.makeButton.TabIndex = 0;
            this.makeButton.Text = "Make";
            this.makeButton.UseVisualStyleBackColor = true;
            this.makeButton.Click += new System.EventHandler(this.makeButton_Click);
            // 
            // frm19CreateWordDoc
            // 
            this.AcceptButton = this.makeButton;
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(284, 61);
            this.Controls.Add(this.makeButton);
            this.Name = "frm19CreateWordDoc";
            this.Text = "CreateWordDoc";
            this.ResumeLayout(false);

        }

        #endregion

        private System.Windows.Forms.Button makeButton;
    }
}