By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,526 Members | 1,895 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,526 IT Pros & Developers. It's quick & easy.

Delegate problem displaying windows form

P: n/a
Hi,

my 'project' requires that I create a form with text info. at set time periods. These time periods are not evenly spaced so I pass a param for the delay(seconds). In order to debug this I have created a form with a button, textbox and NumericUpDown. Textbox holds the message to be displayed on the newly created form and the NumericUpDown allows for set of delay.

I have this working to a fashion but my new form (frm) is not fully repainting itself...in fact the component for displaying the text, which is a label and is the only component manipulated outside of the form class is not being displayed.

I can enter a delay, enter some text and hot the button. After the given delay the form will display as described (with label background opacity appearing = 0). If I try to create two forms these will both appear at the correct times..but both still have the flaw. I don't know what I am doing wrong...or more likely what I am not doing.

Here's the code. I hope someone can help me!!

Cheers, Phil

Imports System.Threading

Public Class frmDelegate
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Delegate Function SleeperDelegate(ByVal tmr As Integer, ByVal msg As String) As String

Dim delSleeperDelegate As SleeperDelegate
Dim cbk As AsyncCallback
Dim res As IAsyncResult
Dim frm As Form1

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

cbk = New AsyncCallback(AddressOf TimeComplete)
delSleeperDelegate = New SleeperDelegate(AddressOf MsgTimer)

End Sub

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

Dim Message As String = txtMsg.Text
Dim intWait As Integer = updn.Value * 60 * 1000
res = delSleeperDelegate.BeginInvoke(intWait, Message, cbk, Nothing)

End Sub

Private Function MsgTimer(ByVal tmr As Integer, ByVal msg As String) As String

Thread.CurrentThread.Sleep(tmr)
Return msg

End Function

Private Sub TimeComplete(ByVal res As IAsyncResult)Dim result As String = delSleeperDelegate.EndInvoke(res)

frm = New Form1
frm.Label1.Text = result
frm.Text = result
frm.Show()

End Sub

End Class

Jan 1 '06 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.