VB.Net/GUI/SendKeys — различия между версиями

Материал из VB Эксперт
Перейти к: навигация, поиск
м (1 версия)
 
(нет различий)

Версия 16:40, 26 мая 2010

Using SendKeys to simulate key press

  
Imports System.Windows.Forms
Imports System.Drawing
Public Class Form1
    Inherits System.Windows.Forms.Form
    Public Sub New()
        MyBase.New()
        InitializeComponent()
    End Sub
    Friend WithEvents PictureBox1 As System.Windows.Forms.PictureBox
    Friend WithEvents Button1 As System.Windows.Forms.Button
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.PictureBox1 = New System.Windows.Forms.PictureBox()
        Me.Button1 = New System.Windows.Forms.Button()
        Me.SuspendLayout()
        "
        Me.PictureBox1.Location = New System.Drawing.Point(288, 16)
        Me.PictureBox1.Size = New System.Drawing.Size(192, 136)
        Me.PictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage
        "
        Me.Button1.Location = New System.Drawing.Point(32, 40)
        Me.Button1.Size = New System.Drawing.Size(208, 40)
        Me.Button1.Text = "Capture the Screen"
        "
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(496, 166)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Button1, Me.PictureBox1})
        Me.Text = "Capturing the Screen, Quick and Easy"
        Me.ResumeLayout(False)
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        GetScreenCapture(True).Save("c:\screengrab.bmp")
        PictureBox1.Image = GetScreenCapture()
    End Sub
    Public Function GetScreenCapture( _
        Optional ByVal FullScreen As Boolean = False) As Image
        Dim objSK As SendKeys
        Dim imgCapture As Image
        If FullScreen = True Then
            objSK.SendWait("{PRTSC 2}")
        Else
            objSK.SendWait("%{PRTSC}")
        End If
        Dim objData As IDataObject = Clipboard.GetDataObject()
        Return objData.GetData(DataFormats.Bitmap)
    End Function
End Class