Popup Form Class Problems
-
I am creating an application that will create a notify window similar to outlook 2003 notify popup. I am making an asyncronous remoting call using system.thread that raises an event to show the form. However, the form shows up as a black box and then immediately disappears when the event is called. If I call the function through a menu item or button, it works fine. Here's the popup code:
Private Sub ATU\_RetrieveDone(ByVal e As AsyncUpdater.AsyncUpdaterEventArgs) Handles ATU.RetrieveDone Me.UpdateTimer.Enabled = False If e.Forums Is Nothing Then UpdateTopicListView(e.Results) ' Updates a list view and ' displays the popup. Else UpdateForumListView(e.Forums) End If Me.UpdateTimer.Enabled = True End Sub Private Sub UpdateTopicListView(ByVal Topics As ResultsCollection) For index As Integer = 0 To Topics.Count - 1 ... Next Dim Message As String Message = "{0} new topic updates have been retrieved from {1}" Me.ShowPopup(String.Format(Message, Topics.Count, ClientSettings.WebURL)) End Sub Private Sub ShowPopup(ByVal Message As String, Optional ByVal TimeOut As Integer = 0) Dim displaytime As Integer If TimeOut < 1000 Then displaytime = ClientSettings.PopupTime \* 1000 Else displaytime = TimeOut End If Dim PW As New PopupWindow PW.SetProperties(NewMessagePopup.Blend, Message, displaytime) PW.ShowPopup() End Sub
And here's routine that creates the popup using a seperate windows form.
Public Sub ShowPopup() Dim tbl As TaskBarLocation Dim workingArea As Rectangle Dim pt As Point pt = New Point pt.X = 0 : pt.Y = 0 workingArea = SystemInformation.WorkingArea tbl = GetTaskBarLocation() ' Gets an enumerator ' indicating the windows task bar ' location. Select Case tbl Case TaskBarLocation.Bottom pt.X = workingArea.Right - Me.Width pt.Y = workingArea.Bottom - Me.Height Case TaskBarLocation.Left pt.X = workingArea.Left pt.Y = workingArea.Bottom - Me.Height Case TaskBarLocation.Right pt.X = workingArea.Right - Me.Width
-
I am creating an application that will create a notify window similar to outlook 2003 notify popup. I am making an asyncronous remoting call using system.thread that raises an event to show the form. However, the form shows up as a black box and then immediately disappears when the event is called. If I call the function through a menu item or button, it works fine. Here's the popup code:
Private Sub ATU\_RetrieveDone(ByVal e As AsyncUpdater.AsyncUpdaterEventArgs) Handles ATU.RetrieveDone Me.UpdateTimer.Enabled = False If e.Forums Is Nothing Then UpdateTopicListView(e.Results) ' Updates a list view and ' displays the popup. Else UpdateForumListView(e.Forums) End If Me.UpdateTimer.Enabled = True End Sub Private Sub UpdateTopicListView(ByVal Topics As ResultsCollection) For index As Integer = 0 To Topics.Count - 1 ... Next Dim Message As String Message = "{0} new topic updates have been retrieved from {1}" Me.ShowPopup(String.Format(Message, Topics.Count, ClientSettings.WebURL)) End Sub Private Sub ShowPopup(ByVal Message As String, Optional ByVal TimeOut As Integer = 0) Dim displaytime As Integer If TimeOut < 1000 Then displaytime = ClientSettings.PopupTime \* 1000 Else displaytime = TimeOut End If Dim PW As New PopupWindow PW.SetProperties(NewMessagePopup.Blend, Message, displaytime) PW.ShowPopup() End Sub
And here's routine that creates the popup using a seperate windows form.
Public Sub ShowPopup() Dim tbl As TaskBarLocation Dim workingArea As Rectangle Dim pt As Point pt = New Point pt.X = 0 : pt.Y = 0 workingArea = SystemInformation.WorkingArea tbl = GetTaskBarLocation() ' Gets an enumerator ' indicating the windows task bar ' location. Select Case tbl Case TaskBarLocation.Bottom pt.X = workingArea.Right - Me.Width pt.Y = workingArea.Bottom - Me.Height Case TaskBarLocation.Left pt.X = workingArea.Left pt.Y = workingArea.Bottom - Me.Height Case TaskBarLocation.Right pt.X = workingArea.Right - Me.Width
I guess the problem is because you're calling methods/setting properties on the control from another thread. You should use
BeginInvoke
orInvoke
methods on the UI (the Form object in your case) to marshal the call to the UI thread. Regards Senthil _____________________________ My Blog | My Articles | WinMacro