vb.net拷贝剪贴板 vbs获取剪贴板内容
VB.NET怎么复制文件到剪切板,不是复制文件内容!
例如,把文件"E:\新建文件夹\a.txt"复制到剪贴板
成都创新互联2013年至今,先为兴山等服务建站,兴山等地企业,进行企业商务咨询服务。为兴山企业网站制作PC+手机+微官网三网同步一站式服务解决您的所有建站问题。
CreateObject("Shell.Application").NameSpace("E:\新建文件夹").ParseName("a.txt").InvokeVerb "复制(C)"
VB.Net 复制Excel数据到剪贴板,然后粘贴到Listview1,最好提供代码,多谢!
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim Str As String = Clipboard.GetText '获取剪切板数据。
ListView1.View = View.Details
Dim Tit As Boolean = True
Dim Index As Integer = 0 '标题行的列数。
Try
For Each i In Str.Replace(vbLf, "").Split(vbCr)
Dim Str2() As String = i.Split(" ")
If Tit Then '标题行
Tit = False
For Each k In Str2
ListView1.Columns.Add(k)
Next
Index = Str2.Length - 1
Else '非标题行。
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
vb,net怎么实现拖拽文件到文本框和粘贴复制?
第一步,点击VS工具
请点击输入图片描述
第二步,打开后,新建一个Windows窗体应用程序
请点击输入图片描述
第三步,新建完毕后,如图所示
请点击输入图片描述
第四步,拖动文本框与按钮,如图示
请点击输入图片描述
第五步,将剪贴板复制与粘贴代码输入,如图示
请点击输入图片描述
第六步,运行程序
请点击输入图片描述
7
第七步,点击按钮,成功从剪贴板中复制与粘贴操作
请点击输入图片描述
vb.net 2008 我想用代码复制一个文件到剪贴板。 用户然后在QQ对话框中右击粘贴就可直接发送。 代码怎么写
复制什么文件呢?
给你举个例子:复制音频文件
Public Class Form1
'VB.Net复制读取音频文件并复制到剪贴板
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("已经成功将音频数据VB.Net复制到剪贴板!", "51cto提示", MessageBoxButtons.OK, MessageBoxIcon.Information)
Catch ex As Exception
MessageBox.Show("将音频数据复制到剪贴板出现错误,请检查音频文件是否已经存在?", "51cto提示", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
'粘贴剪贴板音频数据并播放
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("剪贴板上不存在指定的音频数据!", "51cto提示", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
'清空剪贴板上的音频数据
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
完善一下答案,现在所谓的复制粘贴文件操作,只是复制文件的地址,然后copy到指定地址,你要做的就是把文件的地址复制到剪贴板就好。所谓的剪切,也就是copy后多了一个delete功能。大同小异。
VB 怎么复制文件至剪切板?
楼主的代码看起来像是vbs,仔细调阅了很多资料,在vbs中无法实现复制文件到剪切板的功能。不过在vb6中是可以实现的,需要依靠一些api函数来完成工作。
建立一个按钮Command1,以下范例是将"C:\a.txt"复制到剪切板,要测试请先建立这个文件。
Option Explicit
Private Declare Function OpenClipboard Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function EmptyClipboard Lib "user32" () As Long
Private Declare Function CloseClipboard Lib "user32" () As Long
Private Declare Function GlobalAlloc Lib "kernel32" (ByVal wFlags As Long, ByVal dwBytes As Long) As Long
Private Declare Function GlobalLock Lib "kernel32" (ByVal hMem As Long) As Long
Private Const GMEM_MOVEABLE = H2
Private Const GMEM_ZEROINIT = H40
Private Declare Function GlobalUnlock Lib "kernel32" (ByVal hMem As Long) As Long
Private Declare Function SetClipboardData Lib "user32" (ByVal wFormat As Long, ByVal hMem As Long) As Long
Private Const CF_HDROP = HF
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Private Type POINTAPI
X As Long
Y As Long
End Type
Private Type DROPFILES
pFiles As Long
pT As POINTAPI
fNC As Long
fWide As Long
End Type
Private Sub Command1_Click()
Dim FileName As String
FileName = "C:\a.txt"
If Dir(FileName) = "" Then Exit Sub
FileName = FileName vbNullChar vbNullChar
Call FileToClipboard(FileName)
End Sub
Private Sub FileToClipboard(ByVal FileName As String)
Dim dFiles As DROPFILES
Dim hMem As Long, MemPtr As Long, Len1 As Long, Len2 As Long
If OpenClipboard(Me.hWnd) = 0 Then Exit Sub
Call EmptyClipboard
Len1 = Len(dFiles)
Len2 = LenB(StrConv(FileName, vbFromUnicode))
hMem = GlobalAlloc(GMEM_MOVEABLE Or GMEM_ZEROINIT, Len1 + Len2)
MemPtr = GlobalLock(hMem)
dFiles.pFiles = Len1
Call CopyMemory(ByVal MemPtr, dFiles, Len1)
Call CopyMemory(ByVal (MemPtr + Len1), ByVal FileName, Len2)
Call GlobalUnlock(hMem)
Call SetClipboardData(CF_HDROP, hMem)
Call CloseClipboard
End Sub
文章标题:vb.net拷贝剪贴板 vbs获取剪贴板内容
分享地址:http://azwzsj.com/article/hejcgj.html