经过长时间学习VB.NET,对于VB.NET复制大家都很了解,在这里和大家分享一下VB.NET复制读取音频文件到剪贴板的小技巧,希望大家有所收获。
- 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
怎么样,VB.NET复制很简单吧,动手试试!
【编辑推荐】