473,473 Members | 2,292 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Get the form which calls some code in a class???

Hi all.

I have a class which performs some tasks for which ever form it get s bound
to using a bindForm methods which accepts a form object.
I'd like to do away with this method as it only ever gets used like this:

BindForm(Me)

Is there anyway, that I can get the form object in the class, when it is
instatianted by the form?
In other words I'd like to be able to get the object that is calling the
code, within the actual code.
It would be a Sender type object.....?

Thanks

Alex
Nov 20 '05 #1
2 1260
"Alex Stevens" <al**@matrixinfotech.co.uk_nospam> schrieb
I have a class which performs some tasks for which ever form it get s
bound to using a bindForm methods which accepts a form object.
I'd like to do away with this method as it only ever gets used like
this:

BindForm(Me)

Is there anyway, that I can get the form object in the class, when it
is instatianted by the form?
In other words I'd like to be able to get the object that is calling
the code, within the actual code.
It would be a Sender type object.....?


I don't think it is possible, and if it was possible, I would call it bad
design. Why don't you want to pass the form object? Or, why don't you put
the procedure into the form class? If it is not possible because different
form types need to be passed, why don't you derive all forms from a base
form containing the procedure?
--
Armin

Nov 20 '05 #2
Hi Alex,

Like Armin, I think it's highly dubious. But I'm curious about your
objection to passing in the Form and I'd like to know what it's all about
too!!

If you insist on doing it then I can tell you that this <is> a way. After
all, when you look at a stack trace, it shows the hierarchy of methods and
their parameters and values. The Form that you require would be the main
parameter of the calling method.

System.Diagnostics has a whole load of stuff for querying the stack. You
can easily determine the class of the calling Form but it's probably a lot of
work to get the actual Form object via this route.

Try the following:

Public Function MeAndMyCaller As String
Dim CurrentStack As New System.Diagnostics.StackTrace
Dim Myself As String = CurrentStack.GetFrame(0).GetMethod.Name
Dim MyCaller As String = CurrentStack.GetFrame(1).GetMethod.Name
Dim CallersFrame As StackFrame = CurrentStack.GetFrame(1)
Dim CallerType As Type = CallersFrame.GetMethod.ReflectedType
Dim S As String = CurrentStack.ToString & vbCrLf & vbCrLf
S = S & "In: " & Myself & vbCrLf _
& "Called by: " & MyCaller & vbCrLf _
& "Caller Type: " & CallerType.ToString
MsgBox (S)
End Function

You'll see that you can get names and types but getting object references
is going to take more investigation.

Do tell us what it's about. :-)

Regards,
Fergus
Nov 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Gregory A Greenman | last post by:
I'm trying to write a program in vb.net to automate filling out a series of forms on a website. There are three forms I need to fill out in sequence. The first one is urlencoded. My program is...
10
by: Noozer | last post by:
Below is some ASP, HTML and javascript. It is part of a page used to maintain a small database. This code did work at one time, but has since stopped. For some reason the data on my form is not...
4
by: Stuart Perryman | last post by:
Hi, I have the following code which works just fine in IE6 but not in Firefox. It is an extract of several table rows each with an individual form. It is generated by php. <form...
4
by: dbuchanan | last post by:
Is the following behavior normal? Both the 'Protected sub' in the inherited form and the 'Private Shadows sub' in the derived form fires. My interpretation of MSDN help on the topic "Shadows"...
7
by: gerryLowry::Ability Business Computer Services {KC | last post by:
"Getting Back Your Visual Basic 6.0 Goodies" by Billy Hollis, 2003-5-14, states: "Getting a Forms Collection Visual Basic 6.0 developers are often fond of looping through the currently loaded...
1
by: Steve | last post by:
I need to update my UI from a Process or worker thread. I did some readinf and basically ended up adapting an MS example to fot my needs. It all made sense until I tried it :) My process...
5
by: Miro | last post by:
I will try my best to ask this question correctly. I think in the end the code will make more sence of what I am trying to accomplish. I am just not sure of what to search for on the net. I...
19
by: rbrowning1958 | last post by:
Hello, I am confused by dispose etc. and hope someone can set me right. 1. The Dispose(Bool) the IDE generates for a form has nothing to do with IDisposable, right? 2. So when is this called?...
6
by: Thom Little | last post by:
Using C# 3.5 I have a form that calls many other sub-forms. Typically there will be five forms open at the same time. If the main form is closed all the sub forms are also closed. Is there...
9
by: Brad Pears | last post by:
I have the following code that references a "textbox" on a form. I want to pass the value of this textbox to a stored procedure as a parameter. This code is located on a different form obviously. I...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.