|
-
February 7th, 2005, 03:22 PM
#1
OnClick
I have this code:
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?!
-
February 7th, 2005, 03:28 PM
#2
Re: OnClick
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.
-
February 7th, 2005, 03:31 PM
#3
Re: OnClick
So when I get rid of the message box completely, why doesn't the array element get set?
-
February 7th, 2005, 03:56 PM
#4
Re: OnClick
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.
-
February 7th, 2005, 05:09 PM
#5
Re: OnClick
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.
Code:
// 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
Darwen.
Last edited by darwen; February 7th, 2005 at 05:22 PM.
-
February 8th, 2005, 11:30 AM
#6
Re: OnClick
Thanks for the help! I solved the problem by calling Invalidate() after setting the array item.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|