locked
Invoke or BeginInvoke cannot be called on a control until the window handle has been created. RRS feed

  • Question

  • Dear all,

    I have below code which prompt the above messages.

     this.Controls.Add(this.uC_Banner1);

    Do you know why? How to solve??

    Wednesday, July 4, 2012 8:08 AM

Answers

  • Do you know which window is the one not yet created?  I see two possibilities:  The this pointer probably points to a form or a usercontrol, which would be possiblity #1, or this other uC_Banner1, which sounds like UserControl called Banner or similar.  At which point is this code run?  What event or what function?  Is this in a constructor?

    The idea here would be to execute that code as late in the control or form's lifecycle as possible.  For example, instead of the form's constructor, code that in the Form's Load event.

    If you still have trouble, I guess you can always try to force the handle creation by calling CreateControl().


    Jose R. MCP
    Code Samples

    • Marked as answer by Raymond Chiu Tuesday, July 10, 2012 7:19 AM
    Wednesday, July 4, 2012 3:34 PM

All replies

  • Do you know which window is the one not yet created?  I see two possibilities:  The this pointer probably points to a form or a usercontrol, which would be possiblity #1, or this other uC_Banner1, which sounds like UserControl called Banner or similar.  At which point is this code run?  What event or what function?  Is this in a constructor?

    The idea here would be to execute that code as late in the control or form's lifecycle as possible.  For example, instead of the form's constructor, code that in the Form's Load event.

    If you still have trouble, I guess you can always try to force the handle creation by calling CreateControl().


    Jose R. MCP
    Code Samples

    • Marked as answer by Raymond Chiu Tuesday, July 10, 2012 7:19 AM
    Wednesday, July 4, 2012 3:34 PM
  • Hi Raymond,

    How is it going with Jose's suggestion?

    Any update to the issue?

    If the issue is not solved yet, could you please share a demo with us?
    Best Regards,


    Bob Wu [MSFT]
    MSDN Community Support | Feedback to us

    Monday, July 9, 2012 9:21 AM