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;

namespace MultipleClipboardFormats
{
    public partial class frm93MultipleClipboardFormats : Form
    {
        public frm93MultipleClipboardFormats()
        {
            InitializeComponent();
        }

        // Make some RichText to use.
        private void frm93MultipleClipboardFormats_Load(object sender, EventArgs e)
        {
            // Make the WebBrowser display a clear page.
            htmlWebBrowser.Navigate("about:blank");

            string text = "The quick brown fox jumps over the lazy dog.";
            sourceRichTextBox.Text = text;

            sourceRichTextBox.Select(text.IndexOf("quick"), "quick".Length);
            sourceRichTextBox.SelectionFont = new Font(sourceRichTextBox.SelectionFont, FontStyle.Italic);

            sourceRichTextBox.Select(text.IndexOf("brown"), "brown".Length);
            sourceRichTextBox.SelectionFont = new Font(sourceRichTextBox.SelectionFont, FontStyle.Bold);
            sourceRichTextBox.SelectionColor = Color.Brown;

            sourceRichTextBox.Select(text.IndexOf("fox"), "fox".Length);
            sourceRichTextBox.SelectionFont = new Font(sourceRichTextBox.SelectionFont, FontStyle.Bold);
            sourceRichTextBox.SelectionColor = Color.Red;

            sourceRichTextBox.Select(text.IndexOf("jumps over"), "jumps over".Length);
            sourceRichTextBox.SelectionFont = new Font(sourceRichTextBox.SelectionFont, FontStyle.Underline);

            sourceRichTextBox.Select(text.IndexOf("lazy"), "lazy".Length);
            sourceRichTextBox.SelectionFont = new Font(sourceRichTextBox.SelectionFont, FontStyle.Bold);

            sourceRichTextBox.Select(text.IndexOf("dog"), "dog".Length);
            sourceRichTextBox.SelectionFont = new Font(sourceRichTextBox.SelectionFont, FontStyle.Bold);
            sourceRichTextBox.SelectionColor = Color.Blue;

            sourceRichTextBox.Select(0, 0);
        }

        // Copy data to the clipboard in text, RTF, and HTML formats.
        private void btnCopy_Click(object sender, EventArgs e)
        {
            // Make a DataObject.
            DataObject data_object = new DataObject();

            // Add the data in various formats.
            data_object.SetData(DataFormats.Rtf, sourceRichTextBox.Rtf);
            data_object.SetData(DataFormats.Text, sourceRichTextBox.Text);

            string html_text;
            html_text = $@"<html>
  <head><center><b>The Quick Brown Fox</b></center></head>
  <p>
  <body>{sourceRichTextBox.Text}
  </body>
</html>";
            data_object.SetData(DataFormats.Html, html_text);

            // Place the data in the Clipboard.
            Clipboard.SetDataObject(data_object);
        }

        // Paste data from the clipboard in text,
        // RTF, and HTML formats if they are available.
        private void btnPaste_Click(object sender, EventArgs e)
        {
            // Get the DataObject.
            IDataObject data_object = Clipboard.GetDataObject();

            if (data_object.GetDataPresent(DataFormats.Rtf))
            {
                rtfRichTextBox.Rtf = data_object.GetData(DataFormats.Rtf).ToString();
                rtfCodeTextBox.Text = data_object.GetData(DataFormats.Rtf).ToString();
            }
            else
            {
                rtfRichTextBox.Clear();
                rtfCodeTextBox.Clear();
            }

            if (data_object.GetDataPresent(DataFormats.Text))
                textTextBox.Text = data_object.GetData(DataFormats.Text).ToString();
            else textTextBox.Clear();

            if (data_object.GetDataPresent(DataFormats.Html))
            {
                HtmlDocument doc = htmlWebBrowser.Document;
                doc.Body.InnerHtml = data_object.GetData(DataFormats.Html).ToString();
            }
            else htmlWebBrowser.Navigate("about:blank");
        }


        /// <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.textTextBox = new System.Windows.Forms.TextBox();
            this.rtfCodeTextBox = new System.Windows.Forms.TextBox();
            this.label5 = new System.Windows.Forms.Label();
            this.label4 = new System.Windows.Forms.Label();
            this.label3 = new System.Windows.Forms.Label();
            this.label2 = new System.Windows.Forms.Label();
            this.label1 = new System.Windows.Forms.Label();
            this.btnPaste = new System.Windows.Forms.Button();
            this.btnCopy = new System.Windows.Forms.Button();
            this.rtfRichTextBox = new System.Windows.Forms.RichTextBox();
            this.sourceRichTextBox = new System.Windows.Forms.RichTextBox();
            this.htmlWebBrowser = new System.Windows.Forms.WebBrowser();
            this.groupBox1 = new System.Windows.Forms.GroupBox();
            this.groupBox1.SuspendLayout();
            this.SuspendLayout();
            // 
            // textTextBox
            // 
            this.textTextBox.Location = new System.Drawing.Point(323, 40);
            this.textTextBox.Name = "textTextBox";
            this.textTextBox.Size = new System.Drawing.Size(294, 20);
            this.textTextBox.TabIndex = 54;
            // 
            // rtfCodeTextBox
            // 
            this.rtfCodeTextBox.Location = new System.Drawing.Point(16, 83);
            this.rtfCodeTextBox.Multiline = true;
            this.rtfCodeTextBox.Name = "rtfCodeTextBox";
            this.rtfCodeTextBox.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
            this.rtfCodeTextBox.Size = new System.Drawing.Size(294, 116);
            this.rtfCodeTextBox.TabIndex = 53;
            // 
            // label5
            // 
            this.label5.AutoSize = true;
            this.label5.Location = new System.Drawing.Point(320, 71);
            this.label5.Name = "label5";
            this.label5.Size = new System.Drawing.Size(40, 13);
            this.label5.TabIndex = 52;
            this.label5.Text = "HTML:";
            // 
            // label4
            // 
            this.label4.AutoSize = true;
            this.label4.Location = new System.Drawing.Point(320, 24);
            this.label4.Name = "label4";
            this.label4.Size = new System.Drawing.Size(31, 13);
            this.label4.TabIndex = 51;
            this.label4.Text = "Text:";
            // 
            // label3
            // 
            this.label3.AutoSize = true;
            this.label3.Location = new System.Drawing.Point(13, 67);
            this.label3.Name = "label3";
            this.label3.Size = new System.Drawing.Size(59, 13);
            this.label3.TabIndex = 50;
            this.label3.Text = "RTF Code:";
            // 
            // label2
            // 
            this.label2.AutoSize = true;
            this.label2.Location = new System.Drawing.Point(13, 24);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(31, 13);
            this.label2.TabIndex = 49;
            this.label2.Text = "RTF:";
            // 
            // label1
            // 
            this.label1.AutoSize = true;
            this.label1.Location = new System.Drawing.Point(12, 9);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(44, 13);
            this.label1.TabIndex = 48;
            this.label1.Text = "Source:";
            // 
            // btnPaste
            // 
            this.btnPaste.Location = new System.Drawing.Point(441, 26);
            this.btnPaste.Name = "btnPaste";
            this.btnPaste.Size = new System.Drawing.Size(75, 23);
            this.btnPaste.TabIndex = 47;
            this.btnPaste.Text = "Paste";
            this.btnPaste.Click += new System.EventHandler(this.btnPaste_Click);
            // 
            // btnCopy
            // 
            this.btnCopy.Location = new System.Drawing.Point(322, 26);
            this.btnCopy.Name = "btnCopy";
            this.btnCopy.Size = new System.Drawing.Size(75, 23);
            this.btnCopy.TabIndex = 46;
            this.btnCopy.Text = "Copy";
            this.btnCopy.Click += new System.EventHandler(this.btnCopy_Click);
            // 
            // rtfRichTextBox
            // 
            this.rtfRichTextBox.Location = new System.Drawing.Point(16, 40);
            this.rtfRichTextBox.Name = "rtfRichTextBox";
            this.rtfRichTextBox.Size = new System.Drawing.Size(294, 24);
            this.rtfRichTextBox.TabIndex = 45;
            this.rtfRichTextBox.Text = "";
            // 
            // sourceRichTextBox
            // 
            this.sourceRichTextBox.Location = new System.Drawing.Point(12, 25);
            this.sourceRichTextBox.Name = "sourceRichTextBox";
            this.sourceRichTextBox.Size = new System.Drawing.Size(294, 24);
            this.sourceRichTextBox.TabIndex = 44;
            this.sourceRichTextBox.Text = "";
            // 
            // htmlWebBrowser
            // 
            this.htmlWebBrowser.Location = new System.Drawing.Point(323, 87);
            this.htmlWebBrowser.MinimumSize = new System.Drawing.Size(20, 20);
            this.htmlWebBrowser.Name = "htmlWebBrowser";
            this.htmlWebBrowser.Size = new System.Drawing.Size(294, 112);
            this.htmlWebBrowser.TabIndex = 55;
            // 
            // groupBox1
            // 
            this.groupBox1.Controls.Add(this.rtfRichTextBox);
            this.groupBox1.Controls.Add(this.htmlWebBrowser);
            this.groupBox1.Controls.Add(this.label2);
            this.groupBox1.Controls.Add(this.rtfCodeTextBox);
            this.groupBox1.Controls.Add(this.textTextBox);
            this.groupBox1.Controls.Add(this.label3);
            this.groupBox1.Controls.Add(this.label4);
            this.groupBox1.Controls.Add(this.label5);
            this.groupBox1.Location = new System.Drawing.Point(12, 55);
            this.groupBox1.Name = "groupBox1";
            this.groupBox1.Size = new System.Drawing.Size(629, 209);
            this.groupBox1.TabIndex = 56;
            this.groupBox1.TabStop = false;
            this.groupBox1.Text = "Results";
            // 
            // frm93MultipleClipboardFormats
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(652, 277);
            this.Controls.Add(this.groupBox1);
            this.Controls.Add(this.label1);
            this.Controls.Add(this.btnPaste);
            this.Controls.Add(this.btnCopy);
            this.Controls.Add(this.sourceRichTextBox);
            this.Name = "frm93MultipleClipboardFormats";
            this.Text = "MultipleClipboardFormats";
            this.Load += new System.EventHandler(this.frm93MultipleClipboardFormats_Load);
            this.groupBox1.ResumeLayout(false);
            this.groupBox1.PerformLayout();
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion
        private System.Windows.Forms.TextBox textTextBox;
        private System.Windows.Forms.TextBox rtfCodeTextBox;
        private System.Windows.Forms.Label label5;
        private System.Windows.Forms.Label label4;
        private System.Windows.Forms.Label label3;
        private System.Windows.Forms.Label label2;
        private System.Windows.Forms.Label label1;
        internal System.Windows.Forms.Button btnPaste;
        internal System.Windows.Forms.Button btnCopy;
        internal System.Windows.Forms.RichTextBox rtfRichTextBox;
        internal System.Windows.Forms.RichTextBox sourceRichTextBox;
        private System.Windows.Forms.WebBrowser htmlWebBrowser;
        private System.Windows.Forms.GroupBox groupBox1;
    }
}