Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / April 2005

Tip: Looking for answers? Try searching our database.

Showing a Form using a timer

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Chris Q. - 12 Apr 2005 14:59 GMT
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)
       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
           Dim LI As New ListViewItem
           ... Create LI Item ...
           Dim NewB As New Button
           If Not TopicInList(Topics.Item(index).TopicID) Then
               lvNewTopics.Items.Add(LI)
           End If
       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
       PSound.Beep()

       Dim PW As New PopupWindow
       PW.SetProperties(NewMessagePopup.Blend, Message, displaytime)
       PW.ShowPopup()
   End Sub

And here's routine that creates the popup in 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()

       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
               pt.Y = workingArea.Bottom - Me.Height
           Case TaskBarLocation.Top
               pt.X = workingArea.Right - Me.Width
               pt.Y = workingArea.Top
       End Select

       Me.Visible = False
       Me.Show()
       Me.Focus()
       Me.Top = pt.Y
       Me.Left = pt.X
       Me.Visible = True
       tmrStartFade.Enabled = True
   End Sub

I've done some more research and it appears the problem is caused using
timers. I've used both System.Timers.Timer and System.Windows.Forms.Timer and
both give the same result, a black box that appears and then disappears. If I
call the ShowPopup subroutine by clicking a button, it displays correctly. If
the timer causes the form to be displayed, I get the black box.

Here's the logic steps used:
1) Timer.Tick event occurs
2) Tick Handler creates a new AsyncUpdater and invokes the GetUpdate method
3) GetUpdate creates a new thread and begins the remoting call
4) Once GetUpdate has completed the remoting call, the event RetrieveDone is
raised.
5) The main form handles the event causing a list view to update it's list
of items.
6) The ShowPopup method is called to display the popup.

Any help or ideas would be greatly appreciated. I can't understand why the
manual invoking (pressing a button) works but the event handler doesn't.
Signature

Chris Quick

Richard L Rosenheim - 12 Apr 2005 17:28 GMT
You might try putting in an Application.DoEvents or two after the
Me.ShowPopup to give the system time to actual paint the window.

Richard Rosenheim

> 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
[quoted text clipped - 99 lines]
> Any help or ideas would be greatly appreciated. I can't understand why the
> manual invoking (pressing a button) works but the event handler doesn't.
Chris Q. - 12 Apr 2005 17:44 GMT
This helped the form show up. I placed it after the showpopup event. However,
the form disappeared almost immediately. Should I place this in the popup
class as well?

> You might try putting in an Application.DoEvents or two after the
> Me.ShowPopup to give the system time to actual paint the window.
[quoted text clipped - 113 lines]
> > Any help or ideas would be greatly appreciated. I can't understand why the
> > manual invoking (pressing a button) works but the event handler doesn't.
Chris Q. - 12 Apr 2005 18:12 GMT
It appears that the only event that is fired by the PopUp Form is the
Form.Load event. It does not appear that any of the controls' events are ever
processed, even when calling Application.DoEvents().

Any ideas why this might be occuring?

> This helped the form show up. I placed it after the showpopup event. However,
> the form disappeared almost immediately. Should I place this in the popup
[quoted text clipped - 117 lines]
> > > Any help or ideas would be greatly appreciated. I can't understand why the
> > > manual invoking (pressing a button) works but the event handler doesn't.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.