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.
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.