我的 Visual Basic.net 代码有问题
我正在制作“一种”能够记录击键和截屏的儿童监控软件,但我不知道如何在它已经存在时创建一个新的 .bmp 文件。
Try
'the working area excludes all docked toolbars like taskbar, etc.
Dim currentScreen = Screen.FromHandle(Me.Handle).WorkingArea
'create a bitmap of the working area
Using bmp As New Bitmap(currentScreen.Width, currentScreen.Height)
'copy the screen to the image
Using g = Graphics.FromImage(bmp)
g.CopyFromScreen(New Point(0, 0), New Point(0, 0), currentScreen.Size)
End Using
'save the image
'look for the file
If IO.File.Exists(save1.Text) Then
'if exsist then add (2) to the filename
bmp.Save(Save1.text + "(2)" + ".bmp")
'done
End If
bmp.Save(Save1.Text)
End Using
Catch ex As Exception
End Try
End Sub
如您所见,程序检查 bmp 文件是否已存在,如果存在,程序将生成新的 bmp 文件。例如:如果文件 (whatever.bmp) 存在,则不会覆盖它,而是在文件名 exmp: (whatever(2).bmp) 中添加“(2)”。
所以问题是我不想只为这个函数生成几十行代码,我正在寻找一种自动方法来将 (2)、(3)、(4) 或其他任何内容添加到文件名中,如果它已经存在以防止覆盖。
对不起我的英语不好:D
-马特