VB.Net:获取剪贴板内容时出错 [英] VB.Net: Error when getting clipboard content

查看:171
本文介绍了VB.Net:获取剪贴板内容时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

该程序的目的是重命名丢失的文件.当我选择一个文件时,按F8键将其重命名.为什么我不使用循环,因为使用循环时会出现相同的错误.

有人可以帮我吗?

**
将strClip设置为String = Clipboard.GetText()''时出现错误."
在子过程中:Rename_AddSameValue.

***
想告诉我,有很多简单的方法可以做到这一点.
:)

The purpose of this program is to rename lost of files. When I select a file , press F8 to rename it. Why I don''t use loop because have same error when I use loop.

Could anyone help me with this?

**
Error on "Dim strClip As String = Clipboard.GetText()''Get current file name."
in Sub procedure : Rename_AddSameValue.

***
Thinks for tell me there''s much simplet ways to do that.
:)

Public Class Form1

    Private Sub tmr_Tick(ByVal sender As System.Object, _
                         ByVal e As System.EventArgs) Handles tmr.Tick

              If (Win32API.GetAsyncKeyState(Keys.F8) < 0) Then
                Rename_AddSameValue("Test_")

                DownArrow()'press DownArrow jump to next file.

               End If
    End Sub

    Sub Rename_AddSameValue(ByVal strToAdd As String)
        F2()' press F2.

        Sleep(10)
        Ctrl_C()' press Ctrl + C.

        Sleep(10)
        Dim strClip As String = Clipboard.GetText()'Get current file name.

        'Create a new file name by conbine "test_" and current file name.
        Sleep(10)
        strToAdd = strToAdd & strClip

        Sleep(10)
        PasteTxt(strToAdd)'Press Ctrl + V to paste new name.

        Sleep(10)
        EnterPress()'press enter 
    End Sub
End Class

推荐答案

对于初学者,为什么要使用计时器进行手动处理,而应该由KeyPress事件处理.
其次,如果您不告诉我们异常本身是什么,我们将无法为您提供很多其他帮助.我们不是介意读者,您知道...干杯.
For starters, why are you using a timer for a manual process that should be handled by the KeyPress event instead.
Secondly, we can''t really give you a lot of other help if you don''t tell us what the exception itself is. We aren''t mind readers, you know... Cheers.


都错了!

扔掉这段代码,然后从不做任何类似的事情.不要使用计时器来轮询键盘,而应使用.NET提供的键盘输入事件.通常,避免使用计时器.尽可能使用线程代替计时器.

不要使用Thread.Spleep等待某些条件或没有目的.切勿使用立即(硬编码)常量,尤其是对于延迟和字符串.不要在UI开发中模拟按键.在某些特殊情况下,如果按键本身很有趣,就可以使用它,例如,用于播放键盘宏,创建虚拟键盘.

切勿使用自动生成的名称,例如Form1tmr_Tick-它们违反了良好的Microsoft命名约定.总是重命名这些东西以赋予它们语义名称.

这是关于不该做的事.如果您能解释自己的活动目标,我可以告诉您该怎么办.

—SA
All wrong!

Throw out this code and never do anything similar. Don''t poll keyboard using timer, use keyboard input events provided by .NET. In general, avoid using timers; use threads whenever possible instead of timers.

Don''t use Thread.Spleep for waiting for some condition or without purpose. Never use immediate (hard-coded) constants, especially for delays and strings. Don''t simulate key presses in UI development. It might be used is some very special cases when key presses themselves are of interest, for example, for playing keyboard macro, creation of virtual keyboards.

Never use auto-generated names like Form1 or tmr_Tick — they violate good Microsoft naming conventions. Always rename such things to give them semantic names.

This was about what not to do. I could possible tell you what to do if you explain the goals of your activity.

—SA


听起来好像您要尝试重命名很多文件.为此,您应该使用Directory.GetFiles方法.

MSDN链接:
http://msdn.microsoft.com/en-us/library/07wt70x2.aspx [ ^ ]

这是一个链接,在该链接中,使用Directory.GetFiles使用一些示例代码对文件进行了重命名.

http://social.msdn.microsoft.com/论坛/en-us/vblanguage/thread/73FE5D95-81A8-482E-A491-47A91E42EF8A [
It sounds as though what you are attempting to do is rename a lot of files. For this you should use the Directory.GetFiles method.

MSDN Link:
http://msdn.microsoft.com/en-us/library/07wt70x2.aspx[^]

Here is a link where files are being renamed with some sample code using Directory.GetFiles.

http://social.msdn.microsoft.com/forums/en-us/vblanguage/thread/73FE5D95-81A8-482E-A491-47A91E42EF8A[^]

I agree with what the other answers here, your method is not the best way to approach this. But I will give you credit for trying to write code first then asking for help rather than just asking for code.

Regards


这篇关于VB.Net:获取剪贴板内容时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆