Color Dialog and Font Dialog


   

/*
Professional Windows GUI Programming Using C#
by Jay Glynn, Csaba Torok, Richard Conway, Wahid Choudhury, 
   Zach Greenvoss, Shripad Kulkarni, Neil Whitlow

Publisher: Peer Information
ISBN: 1861007663
*/

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace ColorFontDialog
{
    /// <summary>
    /// Summary description for ColorFontDialog.
    /// </summary>
    public class ColorFontDialog : System.Windows.Forms.Form
    {
        private System.Windows.Forms.Button button1;
        private System.Windows.Forms.Button button2;
        private System.Windows.Forms.Label label1;
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.Container components = null;

        public ColorFontDialog()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();
            this.Text = "Font and Color Dialogs";
            this.button1.Text = "&amp;Font";
            this.button2.Text = "&amp;Color";
            this.label1.Text = "Change my FONT and COLOR!";

            //
            // TODO: Add any constructor code after InitializeComponent call
            //
        }

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        protected override void Dispose( bool disposing )
        {
            if( disposing )
            {
                if (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.button1 = new System.Windows.Forms.Button();
            this.button2 = new System.Windows.Forms.Button();
            this.label1 = new System.Windows.Forms.Label();
            this.SuspendLayout();
            // 
            // button1
            // 
            this.button1.Location = new System.Drawing.Point(24, 8);
            this.button1.Name = "button1";
            this.button1.TabIndex = 0;
            this.button1.Text = "button1";
            this.button1.Click += new System.EventHandler(this.button1_Click_1);
            // 
            // button2
            // 
            this.button2.Location = new System.Drawing.Point(120, 8);
            this.button2.Name = "button2";
            this.button2.TabIndex = 1;
            this.button2.Text = "button2";
            this.button2.Click += new System.EventHandler(this.button2_Click);
            // 
            // label1
            // 
            this.label1.Location = new System.Drawing.Point(8, 48);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(280, 48);
            this.label1.TabIndex = 2;
            this.label1.Text = "label1";
            // 
            // ColorFontDialog
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(292, 101);
            this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                          this.label1,
                                                                          this.button2,
                                                                          this.button1});
            this.Name = "ColorFontDialog";
            this.Text = "ColorFontDialog";
            this.ResumeLayout(false);

        }
        #endregion

        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main() 
        {
            Application.Run(new ColorFontDialog());
        }
        private void button2_Click(object sender, System.EventArgs e)
        {
            ColorDialog cd = new ColorDialog();
            cd.AllowFullOpen = true;   // allow custom colors
            //cd.FullOpen = true;   // shows custom colors automatically
            cd.Color = Color.DarkBlue;  // sets the custom color
            //cd.Color = Color.Blue;   // set the basic color

            if(cd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                this.label1.ForeColor = cd.Color;
        }
        private void button1_Click_1(object sender, System.EventArgs e)
        {
            FontDialog fd = new FontDialog();
            fd.ShowColor = true;
            fd.Color = Color.Blue;
            fd.ShowApply = true;   // ColorDialog does not provide this option!!!
            fd.Apply += new EventHandler(ApplyFont);
            if(fd.ShowDialog() != System.Windows.Forms.DialogResult.Cancel)
                ChangeFont(fd);
        }

        private void ApplyFont(object o, EventArgs ea)
        {
            ChangeFont((FontDialog)o);
        }

        private void ChangeFont(FontDialog fd)
        {
            this.label1.Font = fd.Font;
            this.label1.ForeColor = fd.Color;
        }
    }
}

           
          


Display color dialog and get user selection


   

  using System;
  using System.Drawing;
  using System.Collections;
  using System.ComponentModel;
  using System.Windows.Forms;
  using System.Data;

  public class Test
  {
    static void Main() 
    {
        System.Windows.Forms.ColorDialog colorDlg = new System.Windows.Forms.ColorDialog();    
      colorDlg.AnyColor = true;
      colorDlg.ShowHelp = true;  

      if (colorDlg.ShowDialog() != DialogResult.Cancel)
      {
        string strARGB = colorDlg.Color.ToString();
        Console.WriteLine(strARGB);
      }

    }

  }


           
          


Click on me to change the color


   
 

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

public class MainForm : Form {
    private ColorDialog colorDlg;
    private Color currColor = Color.DimGray;

    public MainForm() {
        CenterToScreen();
        colorDlg = new ColorDialog();
        this.MouseDown += new MouseEventHandler(MainForm_MouseDown);
    }

    void MainForm_MouseDown(object sender, MouseEventArgs e) {
        if (colorDlg.ShowDialog() != DialogResult.Cancel) {
            currColor = colorDlg.Color;
            this.BackColor = currColor;
            string strARGB = colorDlg.Color.ToString();
            MessageBox.Show(strARGB, "Color is:");
        }
    }
}

    


Color Converter

   
 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
//

class Form1 : Form {
    private Color theColor;

    public Form1() {
        InitializeComponent();
        tbRed.Text = "0";
        tbGreen.Text = "0";
        tbBlue.Text = "0";
    }

    private void parseRGB() {
        int r, g, b;

        r = Int16.Parse(tbRed.Text);
        r = Math.Min(r, 255);
        g = Int16.Parse(tbGreen.Text);
        g = Math.Min(g, 255);
        b = Int16.Parse(tbBlue.Text);
        b = Math.Min(b, 255);
        theColor = Color.FromArgb(r, g, b);
        tbHue.Text = theColor.GetHue().ToString();
        tbSat.Text = theColor.GetSaturation().ToString();
        tbBright.Text = theColor.GetBrightness().ToString();
        this.Invalidate();
    }

    private void tbRed_TextChanged(object sender, EventArgs e) {
        parseRGB();
    }

    private void tbGreen_TextChanged(object sender, EventArgs e) {
        parseRGB();
    }

    private void tbBlue_TextChanged(object sender, EventArgs e) {
        parseRGB();
    }

    private void Form1_Paint(object sender, PaintEventArgs e) {
        Graphics g = e.Graphics;

        SolidBrush backBrush = new SolidBrush(System.Drawing.SystemColors.Control);
        g.FillRectangle(backBrush, this.ClientRectangle);
        backBrush.Dispose();

        Rectangle r = new Rectangle(10, 80, 100, 40);
        SolidBrush b = new SolidBrush(theColor);
        g.SetClip(this.ClientRectangle);
        g.FillRectangle(b, r);
        b.Dispose();
    }
    private void InitializeComponent() {
        this.tbRed = new System.Windows.Forms.TextBox();
        this.tbGreen = new System.Windows.Forms.TextBox();
        this.label1 = new System.Windows.Forms.Label();
        this.label2 = new System.Windows.Forms.Label();
        this.label3 = new System.Windows.Forms.Label();
        this.tbBlue = new System.Windows.Forms.TextBox();
        this.tbHue = new System.Windows.Forms.TextBox();
        this.tbSat = new System.Windows.Forms.TextBox();
        this.label4 = new System.Windows.Forms.Label();
        this.label5 = new System.Windows.Forms.Label();
        this.label6 = new System.Windows.Forms.Label();
        this.tbBright = new System.Windows.Forms.TextBox();
        this.SuspendLayout();
        // 
        // tbRed
        // 
        this.tbRed.Location = new System.Drawing.Point(45, 10);
        this.tbRed.Name = "tbRed";
        this.tbRed.Size = new System.Drawing.Size(47, 20);
        this.tbRed.TabIndex = 1;
        this.tbRed.TextChanged += new System.EventHandler(this.tbRed_TextChanged);
        // 
        // tbGreen
        // 
        this.tbGreen.Location = new System.Drawing.Point(149, 10);
        this.tbGreen.Name = "tbGreen";
        this.tbGreen.Size = new System.Drawing.Size(47, 20);
        this.tbGreen.TabIndex = 2;
        this.tbGreen.TextChanged += new System.EventHandler(this.tbGreen_TextChanged);
        // 
        // label1
        // 
        this.label1.AutoSize = true;
        this.label1.Location = new System.Drawing.Point(13, 13);
        this.label1.Name = "label1";
        this.label1.Size = new System.Drawing.Size(25, 14);
        this.label1.TabIndex = 8;
        this.label1.Text = "Red";
        // 
        // label2
        // 
        this.label2.AutoSize = true;
        this.label2.Location = new System.Drawing.Point(106, 13);
        this.label2.Name = "label2";
        this.label2.Size = new System.Drawing.Size(36, 14);
        this.label2.TabIndex = 9;
        this.label2.Text = "Green";
        // 
        // label3
        // 
        this.label3.AutoSize = true;
        this.label3.Location = new System.Drawing.Point(212, 13);
        this.label3.Name = "label3";
        this.label3.Size = new System.Drawing.Size(27, 14);
        this.label3.TabIndex = 10;
        this.label3.Text = "Blue";
        // 
        // tbBlue
        // 
        this.tbBlue.Location = new System.Drawing.Point(246, 10);
        this.tbBlue.Name = "tbBlue";
        this.tbBlue.Size = new System.Drawing.Size(47, 20);
        this.tbBlue.TabIndex = 3;
        this.tbBlue.TextChanged += new System.EventHandler(this.tbBlue_TextChanged);
        // 
        // tbHue
        // 
        this.tbHue.Location = new System.Drawing.Point(45, 44);
        this.tbHue.Name = "tbHue";
        this.tbHue.ReadOnly = true;
        this.tbHue.Size = new System.Drawing.Size(47, 20);
        this.tbHue.TabIndex = 4;
        // 
        // tbSat
        // 
        this.tbSat.Location = new System.Drawing.Point(149, 44);
        this.tbSat.Name = "tbSat";
        this.tbSat.ReadOnly = true;
        this.tbSat.Size = new System.Drawing.Size(47, 20);
        this.tbSat.TabIndex = 5;
        // 
        // label4
        // 
        this.label4.AutoSize = true;
        this.label4.Location = new System.Drawing.Point(13, 47);
        this.label4.Name = "label4";
        this.label4.Size = new System.Drawing.Size(25, 14);
        this.label4.TabIndex = 11;
        this.label4.Text = "Hue";
        // 
        // label5
        // 
        this.label5.AutoSize = true;
        this.label5.Location = new System.Drawing.Point(121, 45);
        this.label5.Name = "label5";
        this.label5.Size = new System.Drawing.Size(21, 14);
        this.label5.TabIndex = 12;
        this.label5.Text = "Sat";
        // 
        // label6
        // 
        this.label6.AutoSize = true;
        this.label6.Location = new System.Drawing.Point(205, 47);
        this.label6.Name = "label6";
        this.label6.Size = new System.Drawing.Size(34, 14);
        this.label6.TabIndex = 13;
        this.label6.Text = "Bright";
        // 
        // tbBright
        // 
        this.tbBright.Location = new System.Drawing.Point(246, 42);
        this.tbBright.Name = "tbBright";
        this.tbBright.ReadOnly = true;
        this.tbBright.Size = new System.Drawing.Size(47, 20);
        this.tbBright.TabIndex = 6;
        // 
        // Form1
        // 
        this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
        this.ClientSize = new System.Drawing.Size(431, 217);
        this.Controls.Add(this.tbBright);
        this.Controls.Add(this.tbBlue);
        this.Controls.Add(this.label6);
        this.Controls.Add(this.label5);
        this.Controls.Add(this.label4);
        this.Controls.Add(this.label3);
        this.Controls.Add(this.label2);
        this.Controls.Add(this.label1);
        this.Controls.Add(this.tbSat);
        this.Controls.Add(this.tbHue);
        this.Controls.Add(this.tbGreen);
        this.Controls.Add(this.tbRed);
        this.Name = "Form1";
        this.Text = "Form1";
        this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint);
        this.ResumeLayout(false);
        this.PerformLayout();

    }
    private System.Windows.Forms.TextBox tbRed;
    private System.Windows.Forms.TextBox tbGreen;
    private System.Windows.Forms.Label label1;
    private System.Windows.Forms.Label label2;
    private System.Windows.Forms.Label label3;
    private System.Windows.Forms.TextBox tbBlue;
    private System.Windows.Forms.TextBox tbHue;
    private System.Windows.Forms.TextBox tbSat;
    private System.Windows.Forms.Label label4;
    private System.Windows.Forms.Label label5;
    private System.Windows.Forms.Label label6;
    private System.Windows.Forms.TextBox tbBright;
    [STAThread]
    static void Main() {
        Application.EnableVisualStyles();
        Application.Run(new Form1());
    }
}

    


My Clock Form


   

/*
Professional Windows GUI Programming Using C#
by Jay Glynn, Csaba Torok, Richard Conway, Wahid Choudhury, 
   Zach Greenvoss, Shripad Kulkarni, Neil Whitlow

Publisher: Peer Information
ISBN: 1861007663
*/
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace MyClock
{
    /// <summary>
    /// Summary description for MyClockForm.
    /// </summary>
    public class MyClockForm : System.Windows.Forms.Form
    {
        public System.Timers.Timer timer1;
        private System.Windows.Forms.Label label1;
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.Container components = null;

        public MyClockForm()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            //
            // TODO: Add any constructor code after InitializeComponent call
            //
        }

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        protected override void Dispose( bool disposing )
        {
            if( disposing )
            {
                if (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.timer1 = new System.Timers.Timer();
         this.label1 = new System.Windows.Forms.Label();
         ((System.ComponentModel.ISupportInitialize)(this.timer1)).BeginInit();
         this.SuspendLayout();
         // 
         // timer1
         // 
         this.timer1.Enabled = true;
         this.timer1.SynchronizingObject = this;
         this.timer1.Elapsed += new System.Timers.ElapsedEventHandler(this.OnTimerElapsed);
         // 
         // label1
         // 
         this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
         this.label1.ForeColor = System.Drawing.SystemColors.Highlight;
         this.label1.Location = new System.Drawing.Point(24, 8);
         this.label1.Name = "label1";
         this.label1.Size = new System.Drawing.Size(224, 48);
         this.label1.TabIndex = 0;
         this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
         // 
         // MyClockForm
         // 
         this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
         this.ClientSize = new System.Drawing.Size(292, 69);
         this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                      this.label1});
         this.Name = "MyClockForm";
         this.Text = "My Clock";
         this.Load += new System.EventHandler(this.MyClockForm_Load);
         ((System.ComponentModel.ISupportInitialize)(this.timer1)).EndInit();
         this.ResumeLayout(false);

      }
        #endregion

        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main() 
        {
            Application.Run(new MyClockForm());
        }

        private void MyClockForm_Load(object sender, System.EventArgs e)
        {
            // Set the interval time ( 1000 ms == 1 sec )
            // after which the timer function is activated
            timer1.Interval = 1000 ;
            // Start the Timer
            timer1.Start();
            // Enable the timer. The timer starts now
            timer1.Enabled = true ; 
        }

        private void OnTimerElapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            // The interval has elapsed and this timer function is called after 1 second
            // Update the time now.
            label1.Text = DateTime.Now.ToString();
        }
    }
}


           
          


Clipboard Viewer (All Formats)

   
 


using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Windows.Forms;

class ClipViewAll : Form {
    Panel panelDisplay, panelButtons;
    RadioButton radioChecked;
    string[] astrFormatsSave = new string[0];

    public static void Main() {
        Application.Run(new ClipViewAll());
    }
    public ClipViewAll() {
        panelDisplay = new Panel();
        panelDisplay.Parent = this;
        panelDisplay.Dock = DockStyle.Fill;
        panelDisplay.Paint += new PaintEventHandler(PanelOnPaint);
        panelDisplay.BorderStyle = BorderStyle.Fixed3D;

        Splitter split = new Splitter();
        split.Parent = this;
        split.Dock = DockStyle.Left;

        panelButtons = new Panel();
        panelButtons.Parent = this;
        panelButtons.Dock = DockStyle.Left;
        panelButtons.AutoScroll = true;
        panelButtons.Width = Width / 2;

        Timer timer = new Timer();
        timer.Interval = 1000;
        timer.Tick += new EventHandler(TimerOnTick);
        timer.Enabled = true;
    }
    void TimerOnTick(object obj, EventArgs ea) {
        IDataObject data = Clipboard.GetDataObject();

        string[] astrFormats = data.GetFormats();
        bool bUpdate = false;

        if (astrFormats.Length != astrFormatsSave.Length)
            bUpdate = true;
        else {
            for (int i = 0; i < astrFormats.Length; i++)
                if (astrFormats&#91;i&#93; != astrFormatsSave&#91;i&#93;) {
                    bUpdate = true;
                    break;
                }
        }

        panelDisplay.Invalidate();

        if (!bUpdate)
            return;

        astrFormatsSave = astrFormats;
        panelButtons.Controls.Clear();
        Graphics grfx = CreateGraphics();
        EventHandler eh = new EventHandler(RadioButtonOnClick);
        int cxText = AutoScaleBaseSize.Width;
        int cyText = AutoScaleBaseSize.Height;

        for (int i = 0; i < astrFormats.Length; i++) {
            RadioButton radio = new RadioButton();
            radio.Parent = panelButtons;
            radio.Text = astrFormats&#91;i&#93;;

            if (!data.GetDataPresent(astrFormats&#91;i&#93;, false))
                radio.Text += "*";

            try {
                object objClip = data.GetData(astrFormats&#91;i&#93;);
                radio.Text += " (" + objClip.GetType() + ")";
            } catch {
                radio.Text += " (Exception on GetData or GetType!)";
            }
            radio.Tag = astrFormats&#91;i&#93;;
            radio.Location = new Point(cxText, i * 3 * cyText / 2);
            radio.Size = new Size((radio.Text.Length + 20) * cxText,
                                  3 * cyText / 2);
            radio.Click += eh;
        }
        grfx.Dispose();
        radioChecked = null;
    }
    void RadioButtonOnClick(object obj, EventArgs ea) {
        radioChecked = (RadioButton)obj;
        panelDisplay.Invalidate();
    }
    void PanelOnPaint(object obj, PaintEventArgs pea) {
        Panel panel = (Panel)obj;
        Graphics grfx = pea.Graphics;
        Brush brush = new SolidBrush(panel.ForeColor);

        if (radioChecked == null)
            return;

        IDataObject data = Clipboard.GetDataObject();
        object objClip = data.GetData((string)radioChecked.Tag);

        if (objClip == null)
            return;

        else if (objClip.GetType() == typeof(string)) {
            grfx.DrawString((string)objClip, Font, brush,
                            panel.ClientRectangle);
        } else if (objClip.GetType() == typeof(string&#91;&#93;))   // FileDrop
          {
            string str = string.Join("
", (string&#91;&#93;)objClip);

            grfx.DrawString(str, Font, brush, panel.ClientRectangle);
        } else if (objClip.GetType() == typeof(Bitmap) ||
                   objClip.GetType() == typeof(Metafile) ||
                   objClip.GetType() == typeof(Image)) {
            grfx.DrawImage((Image)objClip, 0, 0);
        } else if (objClip.GetType() == typeof(MemoryStream)) {
            Stream stream = (Stream)objClip;
            byte&#91;&#93; abyBuffer = new byte&#91;16&#93;;
            long lAddress = 0;
            int iCount;
            Font font = new Font(FontFamily.GenericMonospace,
                                   Font.SizeInPoints);
            float y = 0;

            while ((iCount = stream.Read(abyBuffer, 0, 16)) > 0) {
                lAddress += 16;
            }
        }
    }
}

    


Rich-Text Paste

   




using System;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
   
class RichTextPaste: Form
{
     string   strPastedText = "";
     MenuItem miPastePlain, miPasteRTF, miPasteHTML, miPasteCSV;
   
     public static void Main()
     {
          Application.Run(new RichTextPaste());
     }
     public RichTextPaste()
     {
          ResizeRedraw = true;
   
          Menu = new MainMenu();
   
          MenuItem mi = new MenuItem("&amp;Edit");
          mi.Popup += new EventHandler(MenuEditOnPopup);
          Menu.MenuItems.Add(mi);
   
          miPastePlain = new MenuItem("Paste &amp;Plain Text");
          miPastePlain.Click += new EventHandler(MenuEditPastePlainOnClick);
          Menu.MenuItems[0].MenuItems.Add(miPastePlain);
   
          miPasteRTF = new MenuItem("Paste &amp;Rich Text Format");
          miPasteRTF.Click += new EventHandler(MenuEditPasteRTFOnClick);
          Menu.MenuItems[0].MenuItems.Add(miPasteRTF);
   
          miPasteHTML = new MenuItem("Paste &amp;HTML");
          miPasteHTML.Click += new EventHandler(MenuEditPasteHTMLOnClick);
          Menu.MenuItems[0].MenuItems.Add(miPasteHTML);
   
          miPasteCSV = new MenuItem("Paste &amp;Comma-Separated Values");
          miPasteCSV.Click += new EventHandler(MenuEditPasteCSVOnClick);
          Menu.MenuItems[0].MenuItems.Add(miPasteCSV);
     }
     void MenuEditOnPopup(object obj, EventArgs ea)
     {
          miPastePlain.Enabled = Clipboard.GetDataObject().GetDataPresent(typeof(string));
          miPasteRTF.Enabled = Clipboard.GetDataObject().GetDataPresent(DataFormats.Rtf);
          miPasteHTML.Enabled = Clipboard.GetDataObject().GetDataPresent(DataFormats.Html);
          miPasteCSV.Enabled = Clipboard.GetDataObject().GetDataPresent(DataFormats.CommaSeparatedValue);
     }
     void MenuEditPastePlainOnClick(object obj, EventArgs ea)
     {
          IDataObject data = Clipboard.GetDataObject();
   
          if (data.GetDataPresent(typeof(string)))
          {
               strPastedText = (string) data.GetData(typeof(string));
               Invalidate();
          }
     }
     void MenuEditPasteRTFOnClick(object obj, EventArgs ea)
     {
          IDataObject data = Clipboard.GetDataObject();
   
          if (data.GetDataPresent(DataFormats.Rtf))
          {
               strPastedText = (string) data.GetData(DataFormats.Rtf);
               Invalidate();
          }
     }
     void MenuEditPasteHTMLOnClick(object obj, EventArgs ea)
     {
          IDataObject data = Clipboard.GetDataObject();
   
          if (data.GetDataPresent(DataFormats.Html))
          {
               strPastedText = (string) data.GetData(DataFormats.Html);
               Invalidate();
          }
     }
     void MenuEditPasteCSVOnClick(object obj, EventArgs ea)
     {
          IDataObject data = Clipboard.GetDataObject();
   
          if (data.GetDataPresent(DataFormats.CommaSeparatedValue))
          {
               MemoryStream memstr = (MemoryStream) data.GetData("Csv");
               StreamReader streamreader = new StreamReader(memstr);
               strPastedText = streamreader.ReadToEnd();
               Invalidate();
          }
     }
     protected override void OnPaint(PaintEventArgs pea)
     {
          pea.Graphics.DrawString(strPastedText, Font, new SolidBrush(ForeColor),
                          ClientRectangle);
     }
}