Results 1 to 3 of 3

Thread: [RESOLVED] [2005] Loading a form's instance+handle+not visible

  1. #1

    Thread Starter
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Resolved [RESOLVED] [2005] Loading a form's instance+handle+not visible

    Just wondering...

    Is there a way to load an instance of a form, and then call Invoke on it? If I don't show it, it tells me it doesn't have a handle, so Invoke and BeginInvoke can't be called. I found a workaround of accessing the handle (I guess it forces one to be assigned) by just putting fRead.Handle.ToInt32() in the middle of the code, but I'm wondering if there's a smarter way to do it...

    Thanks


    Has someone helped you? Then you can Rate their helpful post.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: [2005] Loading a form's instance+handle+not visible

    From the documentation from the Control.CreateControl method:
    The CreateControl method forces a handle to be created for the control and its child controls. This method is used when you need a handle immediately for manipulation of the control or its children; simply calling a control's constructor does not create the Handle.

    CreateControl does not create a control handle if the control's Visible property is false. You can either call the CreateHandle method or access the Handle property to create the control's handle regardless of the control's visibility, but in this case, no window handles are created for the control's children.
    CreateControl will not work because the form is not visible. CreateHandle is Protected so can only be called within the form. If this functionality should be part of the form itself then you could call CreateHandle at the end of the constructor or else provide a public method that calls CreatHandle internally. Otherwise your accessing the Handle property goes along with the advice in the documentation.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: [RESOLVED] [2005] Loading a form's instance+handle+not visible

    OK, thanks


    Has someone helped you? Then you can Rate their helpful post.

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