Click to See Complete Forum and Search --> : OnClick
tomcant
February 7th, 2005, 02:22 PM
I have this code:
protected override void OnClick(EventArgs e)
{
base.OnClick(e);
//MessageBox.Show("");
game_board.iboard[(MousePosition.Y-Location.Y-30)/62,
(MousePosition.X-Location.X-5)/62]=0;
}
When the message box is commented out, the array element doesn't get set. Why?!
Krzemo
February 7th, 2005, 02:28 PM
When the message box is commented out, the array element doesn't get set. Why?! Because "MessageBox.Show("");" enters the modal loop ...
U must click "OK" to continue with function.
Best regards,
Krzemo.
tomcant
February 7th, 2005, 02:31 PM
So when I get rid of the message box completely, why doesn't the array element get set?
Krzemo
February 7th, 2005, 02:56 PM
why doesn't the array element get set? And why U didn't try to debug it?
Unfortunately, I have no knowledge of Your code design ;)
System.Diagnostic.Debug.Writeline(....
Try to capture arguments debug indexer etc.
Best regards,
Krzemo.
darwen
February 7th, 2005, 04:09 PM
The reason why your commented out code probably works is -
Is the 'OK' button on your MessageBox over your control by any chance ?
Try
(1) Uncommenting the message box
(2) moving your main form to top left of the screen before trying to code.
I think it won't work - depending on the size of your control.
This is because (I'll bet) the cursor is over a position which makes this work because you've moved it to 'OK' button on the MessageBox.
Try this just hitting 'return' to get rid of the message box - again I'll bet it won't work.
It's safer to use this to get the cursor position.
This will take top left of your control (this includes Forms of course) as (0,0) i.e. it's a local position to your control.
// inside your control
Point pointCursor = System.Windows.Forms.Cursor.Position;
Point pointInControl = this.PointToClient(pointCursor);
// pointInControl should be the one you use.
Your code accessing the array if this is the case is obviously wrong and needs to be reworked. I don't know exactly what you're trying to do here so I can't really advise any further.
OK ?
Hope this helps.
If it does - rate !
If it doesn't - reply. Then rate :wave:
Darwen.
tomcant
February 8th, 2005, 10:30 AM
Thanks for the help! I solved the problem by calling Invalidate() after setting the array item.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.