Clipboard.SetDataObject(TextBox1.Text)
創(chuàng)新互聯(lián)公司堅持“要么做到,要么別承諾”的工作理念,服務(wù)領(lǐng)域包括:網(wǎng)站設(shè)計制作、成都網(wǎng)站制作、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣等服務(wù),滿足客戶于互聯(lián)網(wǎng)時代的肅寧網(wǎng)站設(shè)計、移動媒體設(shè)計的需求,幫助企業(yè)找到有效的互聯(lián)網(wǎng)解決方案。努力成為您成熟可靠的網(wǎng)絡(luò)建設(shè)合作伙伴!
復(fù)制textbox1.text的內(nèi)容的剪貼板
Dim p1 As New Point(0, 0)
Dim p2 As New Point(My.Computer.Screen.WorkingArea.Width, My.Computer.Screen.WorkingArea.Height) '除工具欄全屏
Dim pic As New Bitmap(p2.X, p2.Y)
Using g As Graphics = Graphics.FromImage(pic)
g.CopyFromScreen(p1, p1, p2)
PictureBox1.Image = pic
End Using
Clipboard.SetImage(PictureBox1.Image)
截圖到PictureBox1中顯示,然后在把PictureBox1.image放到剪切板中
復(fù)制什么文件呢?
給你舉個例子:復(fù)制音頻文件
Public?Class?Form1??
'VB.Net復(fù)制讀取音頻文件并復(fù)制到剪貼板??
Private?Sub?Button1_Click(ByVal?sender?As?System.Object,?ByVal?e?As?System.EventArgs)?Handles?Button1.Click??
Try??
Dim?MyData?As?Byte()??
MyMyData?=?My.Computer.FileSystem.ReadAllBytes("WindowsXP.wav")??
My.Computer.Clipboard.SetAudio(MyData)??
MessageBox.Show("已經(jīng)成功將音頻數(shù)據(jù)VB.Net復(fù)制到剪貼板!",?"51cto提示",?MessageBoxButtons.OK,?MessageBoxIcon.Information)??
Catch?ex?As?Exception??
MessageBox.Show("將音頻數(shù)據(jù)復(fù)制到剪貼板出現(xiàn)錯誤,請檢查音頻文件是否已經(jīng)存在?",?"51cto提示",?MessageBoxButtons.OK,?MessageBoxIcon.Error)??
End?Try??
End?Sub??
'粘貼剪貼板音頻數(shù)據(jù)并播放??
Private?Sub?Button2_Click(ByVal?sender?As?System.Object,?ByVal?e?As?System.EventArgs)?Handles?Button2.Click??
Try??
Dim?MyData?As?Object??
MyMyData?=?My.Computer.Clipboard.GetData(DataFormats.WaveAudio)??
My.Computer.Audio.Play(MyData,?AudioPlayMode.Background)??
Catch?ex?As?Exception??
MessageBox.Show("剪貼板上不存在指定的音頻數(shù)據(jù)!",?"51cto提示",?MessageBoxButtons.OK,?MessageBoxIcon.Error)??
End?Try??
End?Sub??
'清空剪貼板上的音頻數(shù)據(jù)??
Private?Sub?Button3_Click(ByVal?sender?As?System.Object,?ByVal?e?As?System.EventArgs)?Handles?Button3.Click??
My.Computer.Clipboard.Clear()??
End?Sub??
End?Class
完善一下答案,現(xiàn)在所謂的復(fù)制粘貼文件操作,只是復(fù)制文件的地址,然后copy到指定地址,你要做的就是把文件的地址復(fù)制到剪貼板就好。所謂的剪切,也就是copy后多了一個delete功能。大同小異。
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim Str As String = Clipboard.GetText '獲取剪切板數(shù)據(jù)。
ListView1.View = View.Details
Dim Tit As Boolean = True
Dim Index As Integer = 0 '標(biāo)題行的列數(shù)。
Try
For Each i In Str.Replace(vbLf, "").Split(vbCr)
Dim Str2() As String = i.Split(" ")
If Tit Then '標(biāo)題行
Tit = False
For Each k In Str2
ListView1.Columns.Add(k)
Next
Index = Str2.Length - 1
Else '非標(biāo)題行。
Dim lv As New ListViewItem(Str2(0))
For k = 1 To Index
lv.SubItems.Add(Str2(k))
Next
ListView1.Items.Add(lv)
End If
Next
Catch ex As Exception
End Try
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Clipboard.SetDataObject(TextBox1.Text)
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
TextBox1.Text = Clipboard.GetDataObject().GetData(DataFormats.Text, False)
End Sub
例如,把文件"E:\新建文件夾\a.txt"復(fù)制到剪貼板
CreateObject("Shell.Application").NameSpace("E:\新建文件夾").ParseName("a.txt").InvokeVerb?"復(fù)制(C)"