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) が存在する場合、上書きせずに、ファイル名に "(2)" を追加します exmp: (whatever(2).bmp)。
したがって、問題は、この関数だけのために数十行のコードを生成したくないということです.(2)、(3)、(4)などをファイル名に追加する自動方法を探しています。上書きを防ぐために存在します。
私の悪い英語でごめんなさい:D
-マット