C# TableLayoutPanel MouseMove Too Much CPU
-
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.
-
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.
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.
-
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.
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
-
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 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.
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
-
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
-
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
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.
-
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.
good :) we all need a piece of advice once in a while... does wonders :)