Screen capturing after resizing showing wrong details on the right side

C

C

I have trouble with screen capture with sizes larger than the normal
size. The screen capture command is located outside the normal size of
the screen, so I have to maximise the screen to access it (click it).

When the command resizes the screen, the right hand side of the window
is not seen properly and even varies from time to time. I added a
delay of 1 second, but that does not help either. It shows the same
wrong detail for 1 second and then the picture is taken. Here is the
code.

Private Sub cmdScr3_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles cmdScr3.Click

Me.WindowState = FormWindowState.Normal
Call lblWiden_DoubleClick(lblWiden, e) ' this widens the
screen to 1024 pixels
Threading.Thread.Sleep(1000)
Call ScreenCapture(Me, "p2w.bmp")

End Sub


Sub ScreenCapture(ByVal frm As Windows.Forms.Form, ByVal filnamn
As String)

Dim g1 As Graphics = frm.CreateGraphics
Dim MyImage = New Bitmap(frm.ClientRectangle.Width,
frm.ClientRectangle.Height, g1)
Dim g2 As Graphics = Graphics.FromImage(MyImage)
Dim dc1 As IntPtr = g1.GetHdc
Dim dc2 As IntPtr = g2.GetHdc

BitBlt(dc2, 0, 0, frm.ClientRectangle.Width,
frm.ClientRectangle.Height, dc1, 0, 0, 13369376)
g1.ReleaseHdc() : g2.ReleaseHdc()
MyImage.Save(filnamn, Imaging.ImageFormat.Bmp)
MyImage.Dispose()

End Sub

The problem is not there if the form is resized to smaller than normal
size. When the size is larger (wider), some commands, some text boxes
and labels disappear. Sometimes an additional thick gray vertical line
appears (where the right edge of the screen used to be). Sometimes
command buttons are half painted, text boxes are in wrong colour.

What am I doing wrong? Or how should I get rid of this presumably
Form_Paint problem? Thanks.
 
A

Armin Zingler

Am 02.10.2010 21:05, schrieb C:
I have trouble with screen capture with sizes larger than the normal
size. The screen capture command is located outside the normal size of
the screen, so I have to maximise the screen to access it (click it).

When the command resizes the screen, the right hand side of the window
is not seen properly and even varies from time to time. I added a
delay of 1 second, but that does not help either. It shows the same
wrong detail for 1 second and then the picture is taken. Here is the
code.

....

I'd have many question, or...
- There is Graphics.CopyFromScreen
- Try calling Refresh instead of Sleep after changing window state
to force repainting before capturing.

Does this help?
 
C

C

Am 02.10.2010 21:05, schrieb C:




I'd have many question, or...
- There is Graphics.CopyFromScreen
- Try calling Refresh instead of Sleep after changing window state
  to force repainting before capturing.

Does this help?

Yes, it does. Thanks. Why does Me.Invalidate not have the same effect
as Me.Refresh?
 
A

Armin Zingler

Am 03.10.2010 11:30, schrieb C:
Yes, it does. Thanks. Why does Me.Invalidate not have the same effect
as Me.Refresh?

From http://msdn.microsoft.com/en-us/library/dd145002(VS.85).aspx:

"The InvalidateRect function adds a rectangle to the specified window's
update region. The update region represents the portion of the window's
client area that must be redrawn."

The same applies to the Invalidate method because it only wraps the API
function.

Further:
"The invalidated areas accumulate in the update region until the region
is processed when the next WM_PAINT message occurs or until the region
is validated by using the ValidateRect or ValidateRgn function.

The system sends a WM_PAINT message to a window whenever its update
region is not empty and there are no other messages in the application
queue for that window."

In .Net, WM_PAINT leads to OnPaint and the Paint event.

The Refresh method calls Invalidate + Update. The Update method is
a wrapper for the UpdateWindow API function:
http://msdn.microsoft.com/en-us/library/dd145167(VS.85).aspx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top