I am having trouble with a screen save. Basically this part of code modifies some labels and pictures, takes a screen capture of the Form2 and places the screen capture image into picFrmMain. The issue is (I think) in FunQuestionOne, as you can see I change the labels around and then call the function GetFormImage but for some reason when I get the image it is without any of the changes to the label. I have a button that calls GetFormImage and it works fine but for some reason FunQuestionOne seems to be initiating the GetFormImage function before the labels are finished.
Any suggestions?
Thanks,
Code:‘In Form2 code Private Sub FunQuestionOne() picYes.Visible = False picNo.Visible = False lbltQuestion.Visible = True lblQuestion.Text = "MAIN QUESTION:..." editbuttoncontrols(pic1, 3, 1, 8) editlabelcontrols(lbl1, "ANSWER1", 20, 2, 4, 9) editbuttoncontrols(pic2, 3, 1, 12) editlabelcontrols(lbl2, "ANSWER2", 20, 2, 4, 13) frmMain.GetFormImage() End Sub ‘In form1 Public Sub GetFormImage() Dim g As Graphics = SecondForm.CreateGraphics() Dim s As Size = SecondForm.Size formImage = New Bitmap(s.Width, s.Height, g) Dim mg As Graphics = Graphics.FromImage(formImage) Dim dc1 As IntPtr = g.GetHdc Dim dc2 As IntPtr = mg.GetHdc ' added code to compute and capture the form ' title bar and borders Dim widthDiff As Integer = _ (SecondForm.Width - SecondForm.ClientRectangle.Width) Dim heightDiff As Integer = _ (SecondForm.Height - SecondForm.ClientRectangle.Height) Dim borderSize As Integer = 0 'widthDiff \ 2 Dim heightTitleBar As Integer = heightDiff - borderSize BitBlt(dc2, 0, 0, _ SecondForm.ClientRectangle.Width + widthDiff, _ SecondForm.ClientRectangle.Height + heightDiff, dc1, _ 0 - borderSize, 0 - heightTitleBar, 13369376) g.ReleaseHdc(dc1) mg.ReleaseHdc(dc2) picFrmMain.Image = New System.Drawing.Bitmap(formImage) End Sub




Reply With Quote