0

I am currently trying to allow the user to copy text from a label on a windows form to a clipboard when being clicked, it does copy the text, but it does not copy the font and size as well. If anyone could help me change my code somehow so that the clipboard also copies the font and fontsize along with the text it will be much appreciated.

Here's the code running it:

Private Sub Lbl1_Click(sender As Object, e As EventArgs) Handles Lbl1.Click

    Clipboard.SetText(lbl1.Text)

    popup.Label1.Text = "Text copied to clipboard"
    Dim popupF As New Form
    popupF = popup
    popupF.Show()

End Sub
icebat
  • 4,696
  • 4
  • 22
  • 36

1 Answers1

1

I would do it like this. Create class:

<Serializable>
Private Class LabelText
    Public font As Font
    Public text As String
End Class

Then you can copy it to clipboard like this:

    Dim labelText As New LabelText
    labelText.font = Me.lbl1.Font
    labelText.text = Me.lbl1.Text

    Clipboard.SetData("label", labelText)

and paste it like this:

    Dim labelText As LabelText = Clipboard.GetData("label")

    Me.lbl2.Font = labelText.font
    Me.lbl2.Text = labelText.text
okkko
  • 1,010
  • 1
  • 13
  • 22