Click here to Skip to main content
15,908,634 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: Maintaining form layout despite resolution change Pin
harveyhanson5-Dec-07 22:58
harveyhanson5-Dec-07 22:58 
Questiongroup policy Coding Pin
skhurams5-Dec-07 20:52
skhurams5-Dec-07 20:52 
GeneralRe: group policy Coding Pin
Dave Kreskowiak6-Dec-07 9:22
mveDave Kreskowiak6-Dec-07 9:22 
QuestionHow to display Crystall Reports. Pin
SekharOne5-Dec-07 19:57
SekharOne5-Dec-07 19:57 
AnswerRe: How to display Crystall Reports. Pin
Ujjaval Modi5-Dec-07 20:23
Ujjaval Modi5-Dec-07 20:23 
GeneralRe: How to display Crystall Reports. Pin
.Net Programmer(129399)15-May-08 10:35
.Net Programmer(129399)15-May-08 10:35 
AnswerRe: How to display Crystall Reports. Pin
CKnig5-Dec-07 20:23
CKnig5-Dec-07 20:23 
QuestionThread.Sleep() executed before finishing Paint Event Pin
bj930815-Dec-07 18:01
bj930815-Dec-07 18:01 
I could not find my previous message. So I posted it again with update from Dave Kreskowiak.

Dave: Thanks for your information. I tried your suggestion. However, I could not call Paint Event in sequence. Could you check my simplified code below? Thank you.

Public Class Form1
Dim gl As Integer = 0

Private Sub measure()
Dim i As Integer
For i = 0 To 16
gl = i * gl
If gl = 256 Then
gl = 255
End If
Panel1.Invalidate()
System.Threading.Thread.Sleep(200)
Next
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Panel1.Invalidate()

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
measure()
End Sub

Private Sub Panel1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint
Panel1.BackColor = Color.FromArgb(gl, gl, gl)
End Sub
End Class

------------------------------Replay from Dave Kreskowiak on 12/2/07 --------------------------------

You cannot put this loop and sleep code in the paint event. Think of the Paint event like a moment in time. It's used to paint a single frame of an animation.

Move the loop and sleep code outside the Paint event and keep track of what the Paint event needs to draw what you want outside the event code. Inside your loop, you update the variables holding the data the paint event needs, call Invalidate on your panel control, then Sleep.



A guide to posting questions on CodeProject[^]
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007

------------------------------ Original message-----------------------------------------------------
I used e.Graphics.Clear in Panel.Paint to change gray level of the Panel. Thread.Sleep() was added to set a time delay between pattern update and measurement. However, this delay function did not work as I expected. Image pattern would be updated after Thread.Sleep(), and take measurement right away. I wonder how you add delay function in VB.NET. Please advise this question. Thank you.

Steven

Public Sub PanelPG_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PanelPG.Paint
for i = 0 to 16
gl = i * 16
e.Graphics.Clear(Color.FromArgb(gl, gl, gl))
System.Threading.Thread.Sleep(200)

objCa.Measure()
Next i

SaveData()

End Sub
GeneralRe: Thread.Sleep() executed before finishing Paint Event Pin
CKnig5-Dec-07 18:23
CKnig5-Dec-07 18:23 
QuestionRe: Thread.Sleep() executed before finishing Paint Event Pin
bj930816-Dec-07 18:27
bj930816-Dec-07 18:27 
GeneralRe: Thread.Sleep() executed before finishing Paint Event Pin
Dave Kreskowiak7-Dec-07 1:37
mveDave Kreskowiak7-Dec-07 1:37 
GeneralRe: Thread.Sleep() executed before finishing Paint Event Pin
bj930817-Dec-07 16:22
bj930817-Dec-07 16:22 
GeneralRe: Thread.Sleep() executed before finishing Paint Event Pin
Dave Kreskowiak8-Dec-07 3:57
mveDave Kreskowiak8-Dec-07 3:57 
GeneralRe: Thread.Sleep() executed before finishing Paint Event [modified] Pin
bj9308110-Dec-07 7:43
bj9308110-Dec-07 7:43 
QuestionHow to free the .dll after unloading the appdomain? Pin
cstrader2325-Dec-07 17:08
cstrader2325-Dec-07 17:08 
AnswerRe: How to free the .dll after unloading the appdomain? Pin
Dave Kreskowiak6-Dec-07 1:37
mveDave Kreskowiak6-Dec-07 1:37 
GeneralRe: How to free the .dll after unloading the appdomain? Pin
cstrader2326-Dec-07 5:47
cstrader2326-Dec-07 5:47 
GeneralBindingSource variable used before being assigned a value Pin
AAGTHosting5-Dec-07 13:12
AAGTHosting5-Dec-07 13:12 
GeneralRe: BindingSource variable used before being assigned a value Pin
Dave Kreskowiak5-Dec-07 16:28
mveDave Kreskowiak5-Dec-07 16:28 
GeneralRe: BindingSource variable used before being assigned a value Pin
AAGTHosting3-Jan-08 9:54
AAGTHosting3-Jan-08 9:54 
GeneralTableAdapter.FillBy Method Pin
AAGTHosting5-Dec-07 10:12
AAGTHosting5-Dec-07 10:12 
GeneralRe: TableAdapter.FillBy Method Pin
Dave Kreskowiak5-Dec-07 11:01
mveDave Kreskowiak5-Dec-07 11:01 
GeneralRe: TableAdapter.FillBy Method Pin
AAGTHosting5-Dec-07 12:20
AAGTHosting5-Dec-07 12:20 
GeneralRe: TableAdapter.FillBy Method Pin
Dave Kreskowiak5-Dec-07 16:24
mveDave Kreskowiak5-Dec-07 16:24 
GeneralRe: TableAdapter.FillBy Method Pin
AAGTHosting3-Jan-08 12:22
AAGTHosting3-Jan-08 12:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.