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. C#
  4. C# TableLayoutPanel MouseMove Too Much CPU

C# TableLayoutPanel MouseMove Too Much CPU

Scheduled Pinned Locked Moved C#
csharphelpquestion
8 Posts 3 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.
  • I Offline
    I Offline
    ikurtz
    wrote on last edited by
    #1

    greetings. i have an issue with the following code. for some reason whenever it is executed it is consuming around 60% of the CPU. this is strange, and was wondering if you had any comments?

    private void HomeTableLayoutPanel\_MouseMove(object sender, MouseEventArgs e) 
    { 
    
        PictureBox HomeCurrentPicBox = (PictureBox)(HomeTableLayoutPanel.GetChildAtPoint(e.Location)); 
        TableLayoutPanelCellPosition HomeCurrentPosition = new TableLayoutPanelCellPosition(-1, -1); 
    
        if (HomeCurrentPicBox != null) 
        { 
            HomeCurrentPosition = HomeTableLayoutPanel.GetCellPosition(HomeCurrentPicBox); 
            gameFormToolTip.SetToolTip(HomeTableLayoutPanel, GameModel.alphaCoords(HomeCurrentPosition.Column) + "," + HomeCurrentPosition.Row.ToString()); 
        } 
    }
    

    thank you for your time.

    K S 2 Replies Last reply
    0
    • I ikurtz

      greetings. i have an issue with the following code. for some reason whenever it is executed it is consuming around 60% of the CPU. this is strange, and was wondering if you had any comments?

      private void HomeTableLayoutPanel\_MouseMove(object sender, MouseEventArgs e) 
      { 
      
          PictureBox HomeCurrentPicBox = (PictureBox)(HomeTableLayoutPanel.GetChildAtPoint(e.Location)); 
          TableLayoutPanelCellPosition HomeCurrentPosition = new TableLayoutPanelCellPosition(-1, -1); 
      
          if (HomeCurrentPicBox != null) 
          { 
              HomeCurrentPosition = HomeTableLayoutPanel.GetCellPosition(HomeCurrentPicBox); 
              gameFormToolTip.SetToolTip(HomeTableLayoutPanel, GameModel.alphaCoords(HomeCurrentPosition.Column) + "," + HomeCurrentPosition.Row.ToString()); 
          } 
      }
      

      thank you for your time.

      K Offline
      K Offline
      Keith Barrow
      wrote on last edited by
      #2

      This is happening beause the method is being called 100s of times when moving the mouse in one "jesture" over a significant distance. Put a breakpoint on and you'll see what I mean, the method is called almost per pixel moved.

      Dalek Dave: There are many words that some find offensive, Homosexuality, Alcoholism, Religion, Visual Basic, Manchester United, Butter.

      1 Reply Last reply
      0
      • I ikurtz

        greetings. i have an issue with the following code. for some reason whenever it is executed it is consuming around 60% of the CPU. this is strange, and was wondering if you had any comments?

        private void HomeTableLayoutPanel\_MouseMove(object sender, MouseEventArgs e) 
        { 
        
            PictureBox HomeCurrentPicBox = (PictureBox)(HomeTableLayoutPanel.GetChildAtPoint(e.Location)); 
            TableLayoutPanelCellPosition HomeCurrentPosition = new TableLayoutPanelCellPosition(-1, -1); 
        
            if (HomeCurrentPicBox != null) 
            { 
                HomeCurrentPosition = HomeTableLayoutPanel.GetCellPosition(HomeCurrentPicBox); 
                gameFormToolTip.SetToolTip(HomeTableLayoutPanel, GameModel.alphaCoords(HomeCurrentPosition.Column) + "," + HomeCurrentPosition.Row.ToString()); 
            } 
        }
        

        thank you for your time.

        S Offline
        S Offline
        Som Shekhar
        wrote on last edited by
        #3

        1. During adding every PictureBox, add an eventhandler for MouseEnter and Leave. This will remove the need for GetChildAtPoint. similarly, find some other places where refactoring could help you avoid repetative control

        I 1 Reply Last reply
        0
        • S Som Shekhar

          1. During adding every PictureBox, add an eventhandler for MouseEnter and Leave. This will remove the need for GetChildAtPoint. similarly, find some other places where refactoring could help you avoid repetative control

          I Offline
          I Offline
          ikurtz
          wrote on last edited by
          #4

          i hear what you are saying but that means i have to do it 200 times! ie th number of pictureboxes im using. im trying to code it short by using table methods.

          S 1 Reply Last reply
          0
          • I ikurtz

            i hear what you are saying but that means i have to do it 200 times! ie th number of pictureboxes im using. im trying to code it short by using table methods.

            S Offline
            S Offline
            Som Shekhar
            wrote on last edited by
            #5

            My Dear, you must have added these controls inside tablelayoutpanel through code only... right? during adding it, you can add an eventhandler. So, this will be done only once... Its easier than you assume. Try it. As a practice, if you need to copypaste a code without a reason, you are doing it wrong. Som

            I 2 Replies Last reply
            0
            • S Som Shekhar

              My Dear, you must have added these controls inside tablelayoutpanel through code only... right? during adding it, you can add an eventhandler. So, this will be done only once... Its easier than you assume. Try it. As a practice, if you need to copypaste a code without a reason, you are doing it wrong. Som

              I Offline
              I Offline
              ikurtz
              wrote on last edited by
              #6

              i get what you are saying now. had not thought of it like that. make all the picturebox share only one method upon event? right?

              1 Reply Last reply
              0
              • S Som Shekhar

                My Dear, you must have added these controls inside tablelayoutpanel through code only... right? during adding it, you can add an eventhandler. So, this will be done only once... Its easier than you assume. Try it. As a practice, if you need to copypaste a code without a reason, you are doing it wrong. Som

                I Offline
                I Offline
                ikurtz
                wrote on last edited by
                #7

                Try it. As a practice, if you need to copypaste a code without a reason, you are doing it wrong. thats the reason im looking into this! i thought i had to issue 100/200 separate picture box events. but i can make them share just the one! thanks for bringing this to attention once again.

                S 1 Reply Last reply
                0
                • I ikurtz

                  Try it. As a practice, if you need to copypaste a code without a reason, you are doing it wrong. thats the reason im looking into this! i thought i had to issue 100/200 separate picture box events. but i can make them share just the one! thanks for bringing this to attention once again.

                  S Offline
                  S Offline
                  Som Shekhar
                  wrote on last edited by
                  #8

                  good :) we all need a piece of advice once in a while... does wonders :)

                  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