How Put the control in memory at run time and paste it on the form at design time

I have created this class:

Friend Class mybutton

    Public Property Location As Point
    Public Property Size As Size
    Public Property BackColor As Color
    Public Property Text As String

    ' some serializers require a simple ctor
    Public Sub New()

    End Sub

    ' create object from passed PB
    Public Sub New(pb As Button)
        Location = pb.Location
        Size = pb.Size
        BackColor = pb.BackColor
        Text = pb.Text
    End Sub

End Class

And in the button event

  ' Create a button at runtime
    Dim button As New mybutton
    button.Text = "Click Me"
    button.Location = New Point(50, 50)

    ' Serialize the button object to a memory stream
    Dim stream As New MemoryStream()
    Dim formatter As New BinaryFormatter()
    formatter.Serialize(stream, button)
    ' stream.Position = 0
    ' Set the memory stream as a custom clipboard format
    Dim dataObject As New DataObject()
    dataObject.SetData("MyButton", stream)
    Clipboard.SetDataObject(dataObject)

Then I ran the program, clicked on the button, closed the program, and tried to paste the result on the form, but I didn't find anything

What should it be



Comments

Popular posts from this blog

Spring Elasticsearch Operations

Network Error and Timeout on Authorize.net JS

Object oriented programming concepts (OOPs)