Announcement

Collapse
No announcement yet.

Screenshot in C#

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Screenshot in C#

    Hiho,

    weiss jemand wo ich ein How-to zum Thema "Screenshots erstellen in C#" finde, falls es so etwas gibt... ?!

    Gruss

  • #2
    Hallo,
    das folgende Beispiel demonstriert einen möglichen Lösungsweg für diese Aufgabe:
    <code>
    [DllImport("user32.dll")]
    <font color="#0000FF">extern</font> <font color="#0000FF">static</font> <font color="#0000FF">void</font> keybd_event(<font color="#0000FF">byte</font> VirtualKeycode, <font color="#0000FF">byte</font> Scan, <font color="#0000FF">int</font> <font color="#008080">Flags</font>, <font color="#0000FF">int</font> ExtraInfo);

    <font color="#0000FF">private</font> <font color="#0000FF">const</font> <font color="#0000FF">byte</font> VK_SNAPSHOT = 0x2C;
    <font color="#0000FF">private</font> <font color="#0000FF">const</font> <font color="#0000FF">byte</font> KEYEVENTF_KEYUP = 0x02;
    <font color="#0000FF">private</font> <font color="#0000FF">const</font> <font color="#0000FF">byte</font> VK_MENU = 0x12;

    <font color="#0000FF">private</font> <font color="#0000FF">void</font> button1_Click(<font color="#0000FF">object</font> sender, System.<font color="#008080">EventArgs</font> e)
    {
    <font color="#008000">// nur aktives Fenster oder der komplette Desktop</font>
    <font color="#0000FF">if</font> (checkBox1.Checked)
    {
    keybd_event(VK_MENU, 0, 0, 0);
    keybd_event(VK_SNAPSHOT, 0, 0, 0);
    keybd_event(VK_SNAPSHOT, 0, KEYEVENTF_KEYUP, 0);
    keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
    }
    <font color="#0000FF">else</font>
    {
    keybd_event(VK_SNAPSHOT, 0, 0, 0);
    keybd_event(VK_SNAPSHOT, 0, KEYEVENTF_KEYUP, 0);
    }
    <font color="#008080">Application</font>.DoEvents();
    pictureBox1.<font color="#008080">Image</font> = (<font color="#008080">Image</font>)<font color="#008080">Clipboard</font>.GetDataObject().GetData(<font color="#008080">DataFormats</font>.<font color="#008080">Bitmap</font>);
    }
    </code>
    Über die Win32-API-Funktion <b>keybd_event</b> wird die DRUCK-Taste ferngesteuert, so dass der von Windows angelegte Screenshot in der Zwischenablage verfügbar ist. Wenn nur das aktive Fenster berücksichtigt werden soll, wird vorher die ALT-Taste ausgelöst

    Comment

    Working...
    X