How to get instance name of form from within that form

Syco54645

Member
Joined
Dec 16, 2007
Messages
9
Programming Experience
5-10
Hello

I am trying to get the instance name of a form from within that formloads function. Example

Dim bob as new form1
bob.show()

So in the form_load code on form1 I am trying to find that the name of the instance is bob. I have looked all over for this but have yet to find anything even talking about it. I would assume that you should use reflection but I am not sure.

Any help would be greatly appreciated

Thanks

-Syco54645
 
It is the variable that is called 'bob', this variable holds a reference to the instance. The instance doesn't have a name, it just an object occupying some part of memory. You can't get the name of any variable that points to this memory address. I also don't see the point of that, why not give the form a name by setting its Name property? bob.Name="bob1", bob.Name="bob2"
 
Because right now i have something of a grid and you double click on an area of the grid and a form pops up that will populate that area of the grid.

the grid is made up of picture boxes and double clicking on a box will bring up an instance of the form that will generate the picture based on user input. I then want to display the picture in that area of the grid (the picture box). To do this i was simply going to see what the current name was of the form (such as bob).

Is there some way that I am missing?

Thanks

-Syco54645
 
To do this you would normally call the form as a dialog (ShowDialog) and retrieve the information the dialog returns.
You can do this any way you want really, but it has nothing to do with the name of the variable.
 
To do this you would normally call the form as a dialog (ShowDialog) and retrieve the information the dialog returns.
You can do this any way you want really, but it has nothing to do with the name of the variable.

Good idea, I did not think of that. I will change it to showdialog then. Still getting used to .net for the third time. How would I go about getting info from the dialog then?
 
Good idea, I did not think of that. I will change it to showdialog then. Still getting used to .net for the third time. How would I go about getting info from the dialog then?
How would you go about getting info from any object? You get property values or call methods and get the return values. Forms are just objects like any other.
 
Oh, I didn't notice there was another question until now :D
If you look at the designer generated code you see the controls are declared with Friend access level. This means you can also access the controls of the other form directly to get information from them; bob.Listbox1.SelectedValue.
 
Back
Top