Using the form handle

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm looking for a way to bring an open form to the top. I know that is I
open a form directly with form1.show() and then later, while the form is open
I do another form1.show(), that I will get original form to pop to the top.
But because I want to have multiple instances of form1 open, I open it with

dim frm as new form1
frm.show()

What I need to do now is reference the opened form from another window and
even pop it to the top if I want to. I've seen that I can capture
frm.Handle. If frm.Handle is 1234;

1) Can I
frm.handle(1234).show()
or
2) Can I
frm.handle(1234).textbox1.text = "Hello"

Thanks
 
Hi Rich,

No, you can't.

Instead of storing the handle why not store a reference to the instance of the Form1 class that you need to show? Then you can just
call frm.Show(), as you mentioned.

You can search for a particular control by index or name as long as you have a reference to the Form.
 
Dave
Thanks for the reponse.
I guess a reference is what I thought I could get with the handle. How
would I obtain a reference that I could later address?
Thanks
 
Hi RichG,

You wrote in your last post, "I've seen that I can capture frm.Handle".

Wherever in code you were going to assign a global variable to frm.Handle, simply store frm instead. Since you need to store
multiple references, you'll have to store a collection of forms.

If your using the 2.0 framework, you can use the following, for example:

Private List<Form> myForms As New List<Form>() 'how do you code generics in VB?

Private Function CreateForm() As Form
Dim frm As New Form1();
myForms.Add(frm)
Return frm
End Function

If you are using an earlier version of the framework just replace the generic list with an ArrayList, for example.

HTH (please forgive me for my lousy VB)
 
Dave said:
Hi RichG,

You wrote in your last post, "I've seen that I can capture frm.Handle".

Wherever in code you were going to assign a global variable to frm.Handle, simply store frm instead. Since you need to store
multiple references, you'll have to store a collection of forms.

If your using the 2.0 framework, you can use the following, for example:

Private List<Form> myForms As New List<Form>() 'how do you code generics in VB?

Private myForms As New List(Of Form)

Think in English... code in English :)
 
Hi Larry,

Thanks for the answer. Very close to proper English, however, I never would have guessed that the use of an 'Of' operator is
required ;)
 
Back
Top