我目前正在尝试允许用户在单击时将文本从Windows窗体上的标签复制到剪贴板,它会复制文本,但它也不会复制字体和大小。如果有人可以帮助我以某种方式更改我的代码,以便剪贴板也复制字体和fontsize以及文本,将非常感激。
以下是运行它的代码:
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
答案 0 :(得分:1)
我会这样做。创建类:
<Serializable>
Private Class LabelText
Public font As Font
Public text As String
End Class
然后你可以像这样将它复制到剪贴板:
Dim labelText As New LabelText
labelText.font = Me.lbl1.Font
labelText.text = Me.lbl1.Text
Clipboard.SetData("label", labelText)
并将其粘贴如下:
Dim labelText As LabelText = Clipboard.GetData("label")
Me.lbl2.Font = labelText.font
Me.lbl2.Text = labelText.text