Windows Develop Bookmark and Share   
 index > Windows Forms General > how to get the name of the form running the procedure from a referenced class?
 

how to get the name of the form running the procedure from a referenced class?

hi all,

i created a Class Library project.. added a procedure that loops thru all the controls in a form.

-----------
Public Shared Sub Check(frm as Form)
Dim ctl As Control = frm.GetNextControl(frm, True)
Do until ctl Is Nothing
'Some codes here.
ctl = frm.GetNextControl(ctl, True)
Loop
End Sub
-----------

this works okay but i'm wanting to not pass an argument form in the procedure. instead, i want the procedure to get the form that invoked it. something like...

-----------
Imports System.Reflection
Public Shared Sub Check()
Dim objMB As MethodBase
Dim objType As Type

objMB = MethodBase.GetCurrentMethod
objType = objMB.DeclaringType

Dim objForm As Object = Activator.CreateInstance(Type.GetType(objType.Assembly.GetName.Name.ToString & "." & objType.Name.ToString))
Dim frm As Object = Directcast(objForm, Form)
Dim ctl As Control = frm.GetNextControl(frm, True)
Do until ctl Is Nothing
'Some codes here.
ctl = frm.GetNextControl(ctl, True)
Loop
End Sub
-----------

the above code is just a sample of what i'm trying to achieve... it's not a working code.

can anyone help me?

thanks
extreme-paranoia  Thursday, April 02, 2009 2:21 AM
That's not possible, there are no object references on the call stack. Nor does it make sense to make your code 10,000 slower just to avoid passing an argument.
Hans Passant.
nobugz  Thursday, April 02, 2009 2:50 AM
That's not possible, there are no object references on the call stack. Nor does it make sense to make your code 10,000 slower just to avoid passing an argument.
Hans Passant.
nobugz  Thursday, April 02, 2009 2:50 AM
Is it possible you can rely onForm.ActiveForm?
ChronusDOTNet  Thursday, April 02, 2009 3:19 AM

You can use google to search for other answers

Custom Search

More Threads

• OpenFileDialog currently active window problem?
• How can I access ProgressBar-> from another class
• Converting Vb.net application to ASP.net application
• ActiveX Control on WinForm
• Restore window from System Tray
• Adding TabPages?-Unlimited
• How to Send Double click message to ListView Control?
• .NET application crashes until it is moved to another directory
• TextBox with Capitalized letters
• Datagridview checkbox column