title: Copy paste control in windows forms C#
body: <p>I am trying to copy paste a control instance using the clipboard. I am able to copy the control but unable to get back the copied object. </p>
  
  <p>Sample code below.</p>
  
  <pre><code>    [Serializable]
  public class myControl
  {
      private Control _copiedControl;
      public myControl(Control ctrl)
      {
          _copiedControl = ctrl;
      }
  
      public Control CopiedControl
      { 
          get 
          {
              return _copiedControl;
          }
          set 
          {
              _copiedControl = value;                
          }
      }
  }
  
  private void btnCopy_Click(object sender,EventArgs e)
  {
      Clipboard.SetData("myControl", new myControl((Control)myButton));
  }          
  
  private void btnPaste_Click(object sender, EventArgs e)
  {
      if(Clipboard.ContainsData("myControl"))
      {
                  // Condition is satisfied here.. 
  
          myControl obj = Clipboard.GetData("myControl") as myControl;
                      // obj is null and control is lost..
          if(obj != null)
          {
              myPanel.Controls.Add(obj.CopiedControl);
          }
      }
  }
  </code></pre>
  
  <p>I am unable to get the copied control using the GetData() method. I am not sure what is wrong can anyone guide me? </p>