EDN Admin
Well-known member
<div style="color:black; background-color:white
<pre><span style="color:blue Imports System.Drawing.Imaging
<span style="color:blue Imports System.Runtime.InteropServices
<span style="color:blue Public <span style="color:blue Class Form1
<DllImport(<span style="color:#a31515 "user32.dll")> _
<span style="color:blue Private <span style="color:blue Shared <span style="color:blue Function GetForegroundWindow() <span style="color:blue As IntPtr
<span style="color:blue End <span style="color:blue Function
<DllImport(<span style="color:#a31515 "user32.dll")> _
<span style="color:blue Public <span style="color:blue Shared <span style="color:blue Function GetWindowRect(<span style="color:blue ByVal hWnd <span style="color:blue As IntPtr, <span style="color:blue ByRef lpRect <span style="color:blue As RECT) <span style="color:blue As <span style="color:blue Boolean
<span style="color:blue End <span style="color:blue Function
<StructLayout(LayoutKind.Sequential)> _
<span style="color:blue Public <span style="color:blue Structure RECT
<span style="color:blue Public Left <span style="color:blue As <span style="color:blue Integer
<span style="color:blue Public Top <span style="color:blue As <span style="color:blue Integer
<span style="color:blue Public Right <span style="color:blue As <span style="color:blue Integer
<span style="color:blue Public Bottom <span style="color:blue As <span style="color:blue Integer
<span style="color:blue End <span style="color:blue Structure
<span style="color:blue Private <span style="color:blue Sub Button1_Click(<span style="color:blue ByVal sender <span style="color:blue As System.Object, <span style="color:blue ByVal e <span style="color:blue As System.EventArgs) <span style="color:blue Handles Button1.Click
<span style="color:blue Dim dialogResult <span style="color:blue As DialogResult = Windows.Forms.DialogResult.Ignore
<span style="color:blue Dim saveName <span style="color:blue As <span style="color:blue String = <span style="color:blue String.Empty
<span style="color:blue Using saveScreenshot <span style="color:blue As SaveFileDialog = <span style="color:blue New SaveFileDialog()
saveScreenshot.Filter = <span style="color:#a31515 "jpg files (*.jpg)|*.jpg"
saveScreenshot.DefaultExt = <span style="color:#a31515 ".jpg"
dialogResult = saveScreenshot.ShowDialog()
<span style="color:blue If dialogResult.<span style="color:blue Equals(dialogResult.OK) <span style="color:blue Then
saveName = saveScreenshot.FileName
<span style="color:blue End <span style="color:blue If
<span style="color:blue End <span style="color:blue Using
<span style="color:blue If dialogResult.<span style="color:blue Equals(dialogResult.OK) <span style="color:blue Then
System.Threading.Thread.Sleep(5000)
<span style="color:blue Dim rct <span style="color:blue As RECT
GetWindowRect(GetForegroundWindow(), rct)
<span style="color:blue Using bmpScreenshot <span style="color:blue As Bitmap = <span style="color:blue New Bitmap(rct.Right - rct.Left, rct.Bottom - rct.Top, PixelFormat.Format24bppRgb)
<span style="color:blue Using gfxScreenshot <span style="color:blue As Graphics = Graphics.FromImage(bmpScreenshot)
gfxScreenshot.CopyFromScreen(rct.Left, rct.Top, 0, 0, <span style="color:blue New Size(rct.Right - rct.Left, rct.Bottom - rct.Top), CopyPixelOperation.SourceCopy)
<span style="color:blue End <span style="color:blue Using
PictureBox1.Image = <span style="color:blue New Bitmap(bmpScreenshot)
bmpScreenshot.Save(saveName, ImageFormat.Jpeg)
<span style="color:blue End <span style="color:blue Using
Console.Beep()
<span style="color:blue End <span style="color:blue If
<span style="color:blue End <span style="color:blue Sub
<span style="color:blue End <span style="color:blue Class
[/code]
Hi
I have used the above to take a snapshot of a panel and save it,
It takes the shot but not at the right position or size obviously,
So I used:
<div style="color:black; background-color:white
<pre> <DllImport(<span style="color:#a31515 "user32.dll")> _
<span style="color:blue Private <span style="color:blue Shared <span style="color:blue Function GetForegroundWindow() <span style="color:blue As IntPtr
<span style="color:blue End <span style="color:blue Function
<DllImport(<span style="color:#a31515 "user32.dll")> _
<span style="color:blue Public <span style="color:blue Shared <span style="color:blue Function GetWindowRect(<span style="color:blue ByVal hWnd <span style="color:blue As IntPtr, <span style="color:blue ByRef lpRect <span style="color:blue As RECT) <span style="color:blue As <span style="color:blue Boolean
<span style="color:blue End <span style="color:blue Function
<StructLayout(LayoutKind.Sequential)> _
<span style="color:blue Public <span style="color:blue Structure RECT
<span style="color:blue Public Left <span style="color:blue As <span style="color:blue Integer
<span style="color:blue Public Top <span style="color:blue As <span style="color:blue Integer
<span style="color:blue Public Right <span style="color:blue As <span style="color:blue Integer
<span style="color:blue Public Bottom <span style="color:blue As <span style="color:blue Integer
<span style="color:blue End <span style="color:blue Structure
<span style="color:blue Private <span style="color:blue Sub Button2_Click(<span style="color:blue ByVal sender <span style="color:blue As System.Object, <span style="color:blue ByVal e <span style="color:blue As System.EventArgs) <span style="color:blue Handles Button2.Click
<span style="color:blue Dim dialogResult <span style="color:blue As DialogResult = Windows.Forms.DialogResult.Ignore
<span style="color:blue Dim saveName <span style="color:blue As <span style="color:blue String = <span style="color:blue String.Empty
<span style="color:blue Using saveScreenshot <span style="color:blue As SaveFileDialog = <span style="color:blue New SaveFileDialog()
saveScreenshot.Filter = <span style="color:#a31515 "jpg files (*.jpg)|*.jpg"
saveScreenshot.DefaultExt = <span style="color:#a31515 ".jpg"
dialogResult = saveScreenshot.ShowDialog()
<span style="color:blue If dialogResult.<span style="color:blue Equals(dialogResult.OK) <span style="color:blue Then
saveName = saveScreenshot.FileName
<span style="color:blue End <span style="color:blue If
<span style="color:blue End <span style="color:blue Using
<span style="color:blue If dialogResult.<span style="color:blue Equals(dialogResult.OK) <span style="color:blue Then
System.Threading.Thread.Sleep(1000)
Console.Beep()
System.Threading.Thread.Sleep(1000)
Console.Beep()
System.Threading.Thread.Sleep(1000)
Console.Beep()
System.Threading.Thread.Sleep(1000)
Console.Beep()
System.Threading.Thread.Sleep(1000)
Console.Beep()
System.Threading.Thread.Sleep(1000)
Console.Beep()
System.Threading.Thread.Sleep(1000)
Console.Beep()
System.Threading.Thread.Sleep(1000)
Console.Beep()
System.Threading.Thread.Sleep(1000)
Console.Beep()
System.Threading.Thread.Sleep(1000)
Console.Beep()
<span style="color:blue Dim rct <span style="color:blue As RECT
GetWindowRect(GetForegroundWindow(), rct)
<span style="color:blue Using bmpScreenshot <span style="color:blue As Bitmap = <span style="color:blue New Bitmap(Panel1.Right - Panel1.Left, Panel1.Bottom - Panel1.Top, PixelFormat.Format32bppRgb)
<span style="color:blue Using gfxScreenshot <span style="color:blue As Graphics = Graphics.FromImage(bmpScreenshot)
gfxScreenshot.CopyFromScreen(rct.Right - Panel1.Left, rct.Bottom - Panel1.Top, 0, 0, <span style="color:blue New Size(Panel1.Width, Panel1.Height), CopyPixelOperation.SourceCopy)
<span style="color:blue End <span style="color:blue Using
bmpScreenshot.Save(saveName, ImageFormat.Jpeg)
<span style="color:blue End <span style="color:blue Using
Console.Beep()
<span style="color:blue End <span style="color:blue If
<span style="color:blue End <span style="color:blue Sub
[/code]
<br/>
and it got the right sized image but not the right position,
Please help
acesr
<br/>
View the full article
<pre><span style="color:blue Imports System.Drawing.Imaging
<span style="color:blue Imports System.Runtime.InteropServices
<span style="color:blue Public <span style="color:blue Class Form1
<DllImport(<span style="color:#a31515 "user32.dll")> _
<span style="color:blue Private <span style="color:blue Shared <span style="color:blue Function GetForegroundWindow() <span style="color:blue As IntPtr
<span style="color:blue End <span style="color:blue Function
<DllImport(<span style="color:#a31515 "user32.dll")> _
<span style="color:blue Public <span style="color:blue Shared <span style="color:blue Function GetWindowRect(<span style="color:blue ByVal hWnd <span style="color:blue As IntPtr, <span style="color:blue ByRef lpRect <span style="color:blue As RECT) <span style="color:blue As <span style="color:blue Boolean
<span style="color:blue End <span style="color:blue Function
<StructLayout(LayoutKind.Sequential)> _
<span style="color:blue Public <span style="color:blue Structure RECT
<span style="color:blue Public Left <span style="color:blue As <span style="color:blue Integer
<span style="color:blue Public Top <span style="color:blue As <span style="color:blue Integer
<span style="color:blue Public Right <span style="color:blue As <span style="color:blue Integer
<span style="color:blue Public Bottom <span style="color:blue As <span style="color:blue Integer
<span style="color:blue End <span style="color:blue Structure
<span style="color:blue Private <span style="color:blue Sub Button1_Click(<span style="color:blue ByVal sender <span style="color:blue As System.Object, <span style="color:blue ByVal e <span style="color:blue As System.EventArgs) <span style="color:blue Handles Button1.Click
<span style="color:blue Dim dialogResult <span style="color:blue As DialogResult = Windows.Forms.DialogResult.Ignore
<span style="color:blue Dim saveName <span style="color:blue As <span style="color:blue String = <span style="color:blue String.Empty
<span style="color:blue Using saveScreenshot <span style="color:blue As SaveFileDialog = <span style="color:blue New SaveFileDialog()
saveScreenshot.Filter = <span style="color:#a31515 "jpg files (*.jpg)|*.jpg"
saveScreenshot.DefaultExt = <span style="color:#a31515 ".jpg"
dialogResult = saveScreenshot.ShowDialog()
<span style="color:blue If dialogResult.<span style="color:blue Equals(dialogResult.OK) <span style="color:blue Then
saveName = saveScreenshot.FileName
<span style="color:blue End <span style="color:blue If
<span style="color:blue End <span style="color:blue Using
<span style="color:blue If dialogResult.<span style="color:blue Equals(dialogResult.OK) <span style="color:blue Then
System.Threading.Thread.Sleep(5000)
<span style="color:blue Dim rct <span style="color:blue As RECT
GetWindowRect(GetForegroundWindow(), rct)
<span style="color:blue Using bmpScreenshot <span style="color:blue As Bitmap = <span style="color:blue New Bitmap(rct.Right - rct.Left, rct.Bottom - rct.Top, PixelFormat.Format24bppRgb)
<span style="color:blue Using gfxScreenshot <span style="color:blue As Graphics = Graphics.FromImage(bmpScreenshot)
gfxScreenshot.CopyFromScreen(rct.Left, rct.Top, 0, 0, <span style="color:blue New Size(rct.Right - rct.Left, rct.Bottom - rct.Top), CopyPixelOperation.SourceCopy)
<span style="color:blue End <span style="color:blue Using
PictureBox1.Image = <span style="color:blue New Bitmap(bmpScreenshot)
bmpScreenshot.Save(saveName, ImageFormat.Jpeg)
<span style="color:blue End <span style="color:blue Using
Console.Beep()
<span style="color:blue End <span style="color:blue If
<span style="color:blue End <span style="color:blue Sub
<span style="color:blue End <span style="color:blue Class
[/code]
Hi
I have used the above to take a snapshot of a panel and save it,
It takes the shot but not at the right position or size obviously,
So I used:
<div style="color:black; background-color:white
<pre> <DllImport(<span style="color:#a31515 "user32.dll")> _
<span style="color:blue Private <span style="color:blue Shared <span style="color:blue Function GetForegroundWindow() <span style="color:blue As IntPtr
<span style="color:blue End <span style="color:blue Function
<DllImport(<span style="color:#a31515 "user32.dll")> _
<span style="color:blue Public <span style="color:blue Shared <span style="color:blue Function GetWindowRect(<span style="color:blue ByVal hWnd <span style="color:blue As IntPtr, <span style="color:blue ByRef lpRect <span style="color:blue As RECT) <span style="color:blue As <span style="color:blue Boolean
<span style="color:blue End <span style="color:blue Function
<StructLayout(LayoutKind.Sequential)> _
<span style="color:blue Public <span style="color:blue Structure RECT
<span style="color:blue Public Left <span style="color:blue As <span style="color:blue Integer
<span style="color:blue Public Top <span style="color:blue As <span style="color:blue Integer
<span style="color:blue Public Right <span style="color:blue As <span style="color:blue Integer
<span style="color:blue Public Bottom <span style="color:blue As <span style="color:blue Integer
<span style="color:blue End <span style="color:blue Structure
<span style="color:blue Private <span style="color:blue Sub Button2_Click(<span style="color:blue ByVal sender <span style="color:blue As System.Object, <span style="color:blue ByVal e <span style="color:blue As System.EventArgs) <span style="color:blue Handles Button2.Click
<span style="color:blue Dim dialogResult <span style="color:blue As DialogResult = Windows.Forms.DialogResult.Ignore
<span style="color:blue Dim saveName <span style="color:blue As <span style="color:blue String = <span style="color:blue String.Empty
<span style="color:blue Using saveScreenshot <span style="color:blue As SaveFileDialog = <span style="color:blue New SaveFileDialog()
saveScreenshot.Filter = <span style="color:#a31515 "jpg files (*.jpg)|*.jpg"
saveScreenshot.DefaultExt = <span style="color:#a31515 ".jpg"
dialogResult = saveScreenshot.ShowDialog()
<span style="color:blue If dialogResult.<span style="color:blue Equals(dialogResult.OK) <span style="color:blue Then
saveName = saveScreenshot.FileName
<span style="color:blue End <span style="color:blue If
<span style="color:blue End <span style="color:blue Using
<span style="color:blue If dialogResult.<span style="color:blue Equals(dialogResult.OK) <span style="color:blue Then
System.Threading.Thread.Sleep(1000)
Console.Beep()
System.Threading.Thread.Sleep(1000)
Console.Beep()
System.Threading.Thread.Sleep(1000)
Console.Beep()
System.Threading.Thread.Sleep(1000)
Console.Beep()
System.Threading.Thread.Sleep(1000)
Console.Beep()
System.Threading.Thread.Sleep(1000)
Console.Beep()
System.Threading.Thread.Sleep(1000)
Console.Beep()
System.Threading.Thread.Sleep(1000)
Console.Beep()
System.Threading.Thread.Sleep(1000)
Console.Beep()
System.Threading.Thread.Sleep(1000)
Console.Beep()
<span style="color:blue Dim rct <span style="color:blue As RECT
GetWindowRect(GetForegroundWindow(), rct)
<span style="color:blue Using bmpScreenshot <span style="color:blue As Bitmap = <span style="color:blue New Bitmap(Panel1.Right - Panel1.Left, Panel1.Bottom - Panel1.Top, PixelFormat.Format32bppRgb)
<span style="color:blue Using gfxScreenshot <span style="color:blue As Graphics = Graphics.FromImage(bmpScreenshot)
gfxScreenshot.CopyFromScreen(rct.Right - Panel1.Left, rct.Bottom - Panel1.Top, 0, 0, <span style="color:blue New Size(Panel1.Width, Panel1.Height), CopyPixelOperation.SourceCopy)
<span style="color:blue End <span style="color:blue Using
bmpScreenshot.Save(saveName, ImageFormat.Jpeg)
<span style="color:blue End <span style="color:blue Using
Console.Beep()
<span style="color:blue End <span style="color:blue If
<span style="color:blue End <span style="color:blue Sub
[/code]
<br/>
and it got the right sized image but not the right position,
Please help
acesr
<br/>
View the full article