CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: OnClick

  1. #1
    Join Date
    Apr 2004
    Location
    Colchester, UK
    Posts
    97

    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?!

  2. #2
    Join Date
    Nov 2004
    Location
    Poland
    Posts
    1,355

    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.

  3. #3
    Join Date
    Apr 2004
    Location
    Colchester, UK
    Posts
    97

    Re: OnClick

    So when I get rid of the message box completely, why doesn't the array element get set?

  4. #4
    Join Date
    Nov 2004
    Location
    Poland
    Posts
    1,355

    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.

  5. #5
    Join Date
    Jan 2002
    Location
    Scaro, UK
    Posts
    5,940

    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.
    www.pinvoker.com - PInvoker - the .NET PInvoke Interface Exporter for C++ Dlls.

  6. #6
    Join Date
    Apr 2004
    Location
    Colchester, UK
    Posts
    97

    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
  •  





Click Here to Expand Forum to Full Width

Featured