Solved

Visual Basic 2010 - How to generate Window Handle without calling 'form.show' first?

Posted on 2010-11-19
5
1,003 Views
Last Modified: 2012-06-27
I'm trying to load a form after I receive data from my client. I pretty much want to load the form AFTER the data has been received and processed.

I have:

I click a button on my mainform to load up a "Creation" form.. I have to use a Invoke to load up the Creation form when getting the data, otherwise the Creation form locks up/acts funny.

So data will be send like this: CreationX.Invoke(dlg, param) to the right form in the module file.  (Dim param(0) As Object, dlg As New delegatedReceiveData(AddressOf processData))

If I do this:

        CreationX = New Creation
        CreationX.Show()

Before sending the data, it works fine and dandy, but If i do this without the .Show, it ends up crashing stating 'CreationX' was pretty much not defined. Issue is, I don't want to .show then .hide just to get it to initialize properly. ({"Invoke or BeginInvoke cannot be called on a control until the window handle has been created."})

So the question is how to generate the window handle WITHOUT calling .Show so I can plug everything in before I call .Show!

Thanks!
0
Comment
Question by:Valleriani
5 Comments
 
LVL 1

Expert Comment

by:DFPercush
ID: 34177708
Load CreationX

Will allocate the object and call Form_Load but not form_init
0
 
LVL 7

Author Comment

by:Valleriani
ID: 34177724
Load(CreationX) doesn't seem to be happy in VB2010. Including Load requiring two variables and possibly 'Raiseevent' before it, but I'm not really sure, coulnd't get it going.

Load(sender as object, e as system.eventargs)
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 34177843
Set Opacity() to 0 (zero) and ShowInTaskBar() to False.  This will allow to you to Show() it without it physically being visible.

*To make it visible at run-time:

    f2.Opacity = 1
Public Class Form1



    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim f2 As New Form2

        f2.Show()



        ' ... proceed to use "f2" ...

    End Sub



End Class



Public Class Form2



    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Me.Opacity = 0

        Me.ShowInTaskbar = False

    End Sub



    Private Sub Form2_Shown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shown

        MessageBox.Show(Me.Handle.ToString("X"))

    End Sub



End Class

Open in new window

0
 
LVL 32

Accepted Solution

by:
Erick37 earned 500 total points
ID: 34178068
It appears that if you access the Handle property of the form, it will get created.
See sample below, which works as long as you read the Handle prior to calling Invoke.
Dim d As New foo(AddressOf foob)



		x = New Form1



		Dim i As IntPtr = x.Handle



		Dim s As String = x.Invoke(d, New Object() {"input"}).ToString



		Debug.WriteLine(s)

Open in new window

0
 
LVL 7

Author Closing Comment

by:Valleriani
ID: 34181381
Thank you. This actually solved it best due to I already was invoking, just didnt call the handle first. Thanks!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now