1

{PRTSC}キー " "を常に送信してから設定するプログラムを作成していますPictureBox1.BackgroundImage = My.Computer.Clipboard.GetImage

最初は正常に動作しますが、1、2 分後に画像ボックスが空白になり、エラーは表示されません。

私のコードは次のとおりです。

Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
    If Not My.Computer.Clipboard.ContainsImage Then
        SendKeys.Send("{PRTSC}")
    Else
        PictureBox1.BackgroundImage = My.Computer.Clipboard.GetImage
        My.Computer.Clipboard.Clear()
    End If
End Sub

私が試してみました:

Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick

    'SendKeys.Send("{PRTSC}")
    'If My.Computer.Clipboard.ContainsImage Then PictureBox1.BackgroundImage = My.Computer.Clipboard.GetImage

    Dim bounds As New Rectangle
    Dim screenshot As System.Drawing.Bitmap
    Dim graph As Graphics
    bounds = Screen.PrimaryScreen.Bounds
    screenshot = New System.Drawing.Bitmap(bounds.Width, bounds.Height) ', System.Drawing.Imaging.PixelFormat.Format32bppRgb)
    graph = Graphics.FromImage(screenshot)
    graph.CopyFromScreen(0, 0, 0, 0, bounds.Size, CopyPixelOperation.SourceCopy)
    PictureBox1.BackgroundImage = screenshot
    graph.Dispose()
    'screenshot.Save("d:\\dcap.jpg", Imaging.ImageFormat.Bmp)

End Sub

ただし、スクリーンショットを破棄しようとすると、すぐにエラーが発生します。どうしてか分かりません。

4

1 に答える 1

0
  1. {PRTSC} は、フォーカスがある場合はアクティブ ウィンドウを取得し、それ以外の場合は画面を取得します。

  2. tick イベントの開始時にタイマーを無効にし、最後に開始することをお勧めします。これにより再エントリが防止され、タイマーの種類 (タイマー コントロール、system.timers.timer、および system.threading.timer があり、それぞれ少しずつ異なります) によっては、再起動が必要になる場合があります。各ティックイベントをタイマーします。

  3. backgroundimage ではなく、picturebox 画像に画像を割り当てるのが普通です。アプリケーション内の何かが picturebox1.image にビットマップを割り当てているか、picturebox1.image を消去している場合、picturebox1.backgroundimage のスクリーン ショットが上書きされます。

于 2015-02-19T17:46:46.790 に答える