Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Question about Invalidate() for VB.Net

Question about Invalidate() for VB.Net

Scheduled Pinned Locked Moved Visual Basic
questioncsharpdebugginghelp
13 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Adam Loudermilk
    wrote on last edited by
    #1

    I was attempting to build an analog clock for my computer. I've got the program just about finished, but I'm having a problem with the form's Invalidate() Function. When I run the program everything works fine for 5-6 seconds, but after that the form won't paint itself anymore. I've checked in debug mode and the loop is still running but the form doesn't paint. So I went a step further and forced the paint event under the mouse_doubleclick(). It is keeping time and the loop is running, but the form won't paint by itself. I have a feeling that the problem is with something that XP is doing behind the scenes. Does anyone know how to solve this problem?

    D L Z 3 Replies Last reply
    0
    • A Adam Loudermilk

      I was attempting to build an analog clock for my computer. I've got the program just about finished, but I'm having a problem with the form's Invalidate() Function. When I run the program everything works fine for 5-6 seconds, but after that the form won't paint itself anymore. I've checked in debug mode and the loop is still running but the form doesn't paint. So I went a step further and forced the paint event under the mouse_doubleclick(). It is keeping time and the loop is running, but the form won't paint by itself. I have a feeling that the problem is with something that XP is doing behind the scenes. Does anyone know how to solve this problem?

      D Offline
      D Offline
      Diego Moita
      wrote on last edited by
      #2

      Adam Loudermilk wrote:

      Does anyone know how to solve this problem?

      Looks like an hardware problem; in the device between the chair and the keyboard. BTW what part of : Please DO NOT POST PROGRAMMING QUESTIONS HERE. If you have a programming question please post it in the programming forums at forums. you don't get?


      Of all forms of sexual aberration, the most unnatural is abstinence.

      A M 2 Replies Last reply
      0
      • D Diego Moita

        Adam Loudermilk wrote:

        Does anyone know how to solve this problem?

        Looks like an hardware problem; in the device between the chair and the keyboard. BTW what part of : Please DO NOT POST PROGRAMMING QUESTIONS HERE. If you have a programming question please post it in the programming forums at forums. you don't get?


        Of all forms of sexual aberration, the most unnatural is abstinence.

        A Offline
        A Offline
        Adam Loudermilk
        wrote on last edited by
        #3

        Thank you for straightening that out for me. I'm new to programming and the CodeProject. It's always nice to have a friendly person show you the way. Thanks for your help Diego Moita, Adam :suss:

        1 Reply Last reply
        0
        • A Adam Loudermilk

          I was attempting to build an analog clock for my computer. I've got the program just about finished, but I'm having a problem with the form's Invalidate() Function. When I run the program everything works fine for 5-6 seconds, but after that the form won't paint itself anymore. I've checked in debug mode and the loop is still running but the form doesn't paint. So I went a step further and forced the paint event under the mouse_doubleclick(). It is keeping time and the loop is running, but the form won't paint by itself. I have a feeling that the problem is with something that XP is doing behind the scenes. Does anyone know how to solve this problem?

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          Hi, you'd better show some code, regarding the timer (initialization and tick handler) and possibly the paint handler (the essence of it, not all the graphic details). :)

          Luc Pattyn [Forum Guidelines] [My Articles]


          Avoiding unwanted divs (as in "articles needing approval") with the help of this FireFox add-in


          A 1 Reply Last reply
          0
          • D Diego Moita

            Adam Loudermilk wrote:

            Does anyone know how to solve this problem?

            Looks like an hardware problem; in the device between the chair and the keyboard. BTW what part of : Please DO NOT POST PROGRAMMING QUESTIONS HERE. If you have a programming question please post it in the programming forums at forums. you don't get?


            Of all forms of sexual aberration, the most unnatural is abstinence.

            M Offline
            M Offline
            Mycroft Holmes
            wrote on last edited by
            #5

            Oops and you thought you were in the Lounge :) Unless of course the original post was in the Lounge and it was moved!

            Never underestimate the power of human stupidity RAH

            1 Reply Last reply
            0
            • A Adam Loudermilk

              I was attempting to build an analog clock for my computer. I've got the program just about finished, but I'm having a problem with the form's Invalidate() Function. When I run the program everything works fine for 5-6 seconds, but after that the form won't paint itself anymore. I've checked in debug mode and the loop is still running but the form doesn't paint. So I went a step further and forced the paint event under the mouse_doubleclick(). It is keeping time and the loop is running, but the form won't paint by itself. I have a feeling that the problem is with something that XP is doing behind the scenes. Does anyone know how to solve this problem?

              Z Offline
              Z Offline
              Zaegra
              wrote on last edited by
              #6

              Doesn't Me.Refresh() work?

              Motivation is the key to software development.

              A 1 Reply Last reply
              0
              • L Luc Pattyn

                Hi, you'd better show some code, regarding the timer (initialization and tick handler) and possibly the paint handler (the essence of it, not all the graphic details). :)

                Luc Pattyn [Forum Guidelines] [My Articles]


                Avoiding unwanted divs (as in "articles needing approval") with the help of this FireFox add-in


                A Offline
                A Offline
                Adam Loudermilk
                wrote on last edited by
                #7

                I don't know how much you need (honestly I didn't think that any would be required to understand the problem). I've copied the timer tick() routine.

                Private Sub ClockTimer_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ClockTimer.Tick
                Me.Invalidate()
                HourHand.Position = System.DateTime.Now.Hour
                MinuteHand.Position = System.DateTime.Now.Minute
                SecondHand.Position = System.DateTime.Now.Second
                Application.DoEvents()
                End Sub

                When the program first starts to run the clock will tick about five times. Then it will pause for about 3 seconds, tick one more time and then it stops. I know that it is something that XP is doing, but I'm unsure of how to force it. I've also changed the styles of the form:

                Me.SetStyle(ControlStyles.UserPaint Or ControlStyles.FixedHeight Or ControlStyles.FixedWidth Or _
                ControlStyles.SupportsTransparentBackColor, True)

                If someone has any idea what this might be I would appreciate you letting me know. Thanks

                L 1 Reply Last reply
                0
                • Z Zaegra

                  Doesn't Me.Refresh() work?

                  Motivation is the key to software development.

                  A Offline
                  A Offline
                  Adam Loudermilk
                  wrote on last edited by
                  #8

                  I tried replacing Me.Invalidate() with Me.Refresh and unfortunately I got the same results. It didn't affect it at all.

                  1 Reply Last reply
                  0
                  • A Adam Loudermilk

                    I don't know how much you need (honestly I didn't think that any would be required to understand the problem). I've copied the timer tick() routine.

                    Private Sub ClockTimer_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ClockTimer.Tick
                    Me.Invalidate()
                    HourHand.Position = System.DateTime.Now.Hour
                    MinuteHand.Position = System.DateTime.Now.Minute
                    SecondHand.Position = System.DateTime.Now.Second
                    Application.DoEvents()
                    End Sub

                    When the program first starts to run the clock will tick about five times. Then it will pause for about 3 seconds, tick one more time and then it stops. I know that it is something that XP is doing, but I'm unsure of how to force it. I've also changed the styles of the form:

                    Me.SetStyle(ControlStyles.UserPaint Or ControlStyles.FixedHeight Or ControlStyles.FixedWidth Or _
                    ControlStyles.SupportsTransparentBackColor, True)

                    If someone has any idea what this might be I would appreciate you letting me know. Thanks

                    L Offline
                    L Offline
                    Luc Pattyn
                    wrote on last edited by
                    #9

                    Hi, the DoEvents() does not belong there, just remove it. and the Me.Invalidate() needs to come after you changed the parameters: first adjust the positions, then tell the Form it needs to be redrawn! I am assuming your Form itself is showing the hands. If that does not solve it, something else is wrong too. One possibility is your system is overloaded and your app does not get a chance to process its message queue. Is Task Manager indicating a high CPU load? :)

                    Luc Pattyn [Forum Guidelines] [My Articles]


                    The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.


                    A 1 Reply Last reply
                    0
                    • L Luc Pattyn

                      Hi, the DoEvents() does not belong there, just remove it. and the Me.Invalidate() needs to come after you changed the parameters: first adjust the positions, then tell the Form it needs to be redrawn! I am assuming your Form itself is showing the hands. If that does not solve it, something else is wrong too. One possibility is your system is overloaded and your app does not get a chance to process its message queue. Is Task Manager indicating a high CPU load? :)

                      Luc Pattyn [Forum Guidelines] [My Articles]


                      The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.


                      A Offline
                      A Offline
                      Adam Loudermilk
                      wrote on last edited by
                      #10

                      Thanks for responding so quick Luc. I would like to get this thing finished. I've been working on it entirely too long. So, I took the DoEvents() out and switched the order of operations like you had said. Still no luck. Then I tried a couple of other things: 1. tried publishing the program to see if it would still act the same as a stand alone app. It compiled but when I try to install it an error comes up and won't install completely. 2. (very strange I know) If you press f5 and minimize the VB window really fast, then go over and double click on the system clock in the system tray the program will run perfectly until you close the "Date and Time Properties" window. After you close the D and T window the program will freeze again in about 4 seconds. I know that the computer is not too busy because I can move the form around the desktop just fine. It doesn't hang up at all. I'm really stumped! Not very sure what to do from here. If anyone has an idea please let me know. There is probably too much code to insert it all in one of these replies. Is there anyway to attach the project folder somehow? Thanks again for your help

                      L 1 Reply Last reply
                      0
                      • A Adam Loudermilk

                        Thanks for responding so quick Luc. I would like to get this thing finished. I've been working on it entirely too long. So, I took the DoEvents() out and switched the order of operations like you had said. Still no luck. Then I tried a couple of other things: 1. tried publishing the program to see if it would still act the same as a stand alone app. It compiled but when I try to install it an error comes up and won't install completely. 2. (very strange I know) If you press f5 and minimize the VB window really fast, then go over and double click on the system clock in the system tray the program will run perfectly until you close the "Date and Time Properties" window. After you close the D and T window the program will freeze again in about 4 seconds. I know that the computer is not too busy because I can move the form around the desktop just fine. It doesn't hang up at all. I'm really stumped! Not very sure what to do from here. If anyone has an idea please let me know. There is probably too much code to insert it all in one of these replies. Is there anyway to attach the project folder somehow? Thanks again for your help

                        L Offline
                        L Offline
                        Luc Pattyn
                        wrote on last edited by
                        #11

                        OK, tell us a lot more about your app. what is its main goal? what special things does it include? third-party stuff? P/Invoke? COM objects? are you painting everything in the Paint handler? are you using CreateGraphics? do you call Dispose() on everything that you created and don't need any longer. open up Task Manager, and watch your app's memory consumption; is it increasing all the time? and what did you mean by "the loop is still running" in your original post? BTW: you can run an app without creating an installer and everything; just open up the project's folder, dive into bin/debug/ (or bin/release) and double-click the exe file (the one without vshost in the name). :)

                        Luc Pattyn [Forum Guidelines] [My Articles]


                        The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.


                        A 1 Reply Last reply
                        0
                        • L Luc Pattyn

                          OK, tell us a lot more about your app. what is its main goal? what special things does it include? third-party stuff? P/Invoke? COM objects? are you painting everything in the Paint handler? are you using CreateGraphics? do you call Dispose() on everything that you created and don't need any longer. open up Task Manager, and watch your app's memory consumption; is it increasing all the time? and what did you mean by "the loop is still running" in your original post? BTW: you can run an app without creating an installer and everything; just open up the project's folder, dive into bin/debug/ (or bin/release) and double-click the exe file (the one without vshost in the name). :)

                          Luc Pattyn [Forum Guidelines] [My Articles]


                          The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.


                          A Offline
                          A Offline
                          Adam Loudermilk
                          wrote on last edited by
                          #12

                          No to everything except; Yes, I'm painting everything in the paint handler, and the program's memory is steady around 41,000K. The application is just eye candy. It doesn't do anything special except look and act like an analog clock that sits on the desktop. When I said "the loop is still running" I was referring to the timer. The timer was still ticking and the Me.Invalidate() function was still being called, but nothing was happening. I've actually come up with a solution that seems to be working. Originally I was painting everything to the form. I inserted a picture box and am painting on that now. So now the paint handler has PicBox.Invalidate() instead of Me.Invalidate(). It's been running for about ten minutes without freezing up. Adding the picture box seems to be the answer to the problem, but I'm still curious why it was not working before. Is there something that Microsoft built into the operating system that keeps the form from painting itself too many times? Thanks for all your help Luc, Adam

                          L 1 Reply Last reply
                          0
                          • A Adam Loudermilk

                            No to everything except; Yes, I'm painting everything in the paint handler, and the program's memory is steady around 41,000K. The application is just eye candy. It doesn't do anything special except look and act like an analog clock that sits on the desktop. When I said "the loop is still running" I was referring to the timer. The timer was still ticking and the Me.Invalidate() function was still being called, but nothing was happening. I've actually come up with a solution that seems to be working. Originally I was painting everything to the form. I inserted a picture box and am painting on that now. So now the paint handler has PicBox.Invalidate() instead of Me.Invalidate(). It's been running for about ten minutes without freezing up. Adding the picture box seems to be the answer to the problem, but I'm still curious why it was not working before. Is there something that Microsoft built into the operating system that keeps the form from painting itself too many times? Thanks for all your help Luc, Adam

                            L Offline
                            L Offline
                            Luc Pattyn
                            wrote on last edited by
                            #13

                            Hi Adam, You're welcome. I don't know about anything special when painting to a Form, but then I tend to always paint to a Panel, I don't want to a Form most of the time, since the drawing to me is an object that I want to be able to move, resize, whatever, independent of the Form. Of course there could be reasons to do it differently. I don't like PictureBoxes that much, they don't do much, and often work against you, when things become somewhat involved. FWIW: you could anchor the Panel or PictureBox, or set its Dock to Fill, so it grows/shrinks with the Form (but yours was fixed, wasn't it?). :)

                            Luc Pattyn [Forum Guidelines] [My Articles]


                            The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.


                            1 Reply Last reply
                            0
                            Reply
                            • Reply as topic
                            Log in to reply
                            • Oldest to Newest
                            • Newest to Oldest
                            • Most Votes


                            • Login

                            • Don't have an account? Register

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • World
                            • Users
                            • Groups