473,802 Members | 2,374 Online
Bytes | Software Development & Data Engineering Community
+ 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 1270
"Alex Stevens" <al**@matrixinf otech.co.uk_nos pam> 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.Diagnost ics 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.Diagnost ics.StackTrace
Dim Myself As String = CurrentStack.Ge tFrame(0).GetMe thod.Name
Dim MyCaller As String = CurrentStack.Ge tFrame(1).GetMe thod.Name
Dim CallersFrame As StackFrame = CurrentStack.Ge tFrame(1)
Dim CallerType As Type = CallersFrame.Ge tMethod.Reflect edType
Dim S As String = CurrentStack.To String & vbCrLf & vbCrLf
S = S & "In: " & Myself & vbCrLf _
& "Called by: " & MyCaller & vbCrLf _
& "Caller Type: " & CallerType.ToSt ring
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
19362
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 able to fill that one out just fine. The second form is multipart/form-data. Unfortunately, I haven't been able to fill that out in a way that makes the server happy. I set up a copy of this form at my web site so that I could see exactly what a...
10
2908
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 being passed to the page specified in the Action property of the form. This is on a Windows 2000 Pro PC. I copied the code to another server (Windows XP Pro machine) and it DOES work as expected there. The first block is the data located near...
4
9304
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 action="MaintNotification.php?ReqID=5" method="post" name="frm5"> <tr align="left" bgcolor="#dddddd" class="text" onClick="submit()"
4
3759
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" does not seem to indicate that this is the designed behavior. (the topic is rather cryptic to me. Here is my code;
7
1861
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 forms in an application to find out something, such as if a particular form it loaded, or how many of a particular type of form are loaded. Windows Forms does not include a Forms collection, however, so gaining such functionality in Visual Basic...
1
4220
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 makes calls to a Singleton logger class which in turn makes calls to a delegate to add items to a listbox in my WinForm. Here is the code that I have in my Form class to log output <code> delegate void AddOutputItem(string msg);
5
10911
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 have a form that has a button. ( this form is a child form of a parent form ( main form ). Anway...in this child form I have a button, and if clicked a bunch of code will get executed. I would like to show a Progress Bar / form in modal/ShowDialog...
19
4653
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? When a form is closed? If this is caused automatically when a form is closed how can I then access things on a modal from after ShowDialog() returns? Or is it only for modeless forms?
6
2276
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 a standard way to gain control within the sub-forms to do individual clean-up prior to their removal?
9
2898
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 thought that I would be able to reference the textbox simply by placing the name of the form it is located on (class name) in front as follows... param1 = frmSteelPlates.txtJobNo.Text I am getting the following error when I debug the line to...
0
9699
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10535
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10303
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10282
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9111
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7598
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6838
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5494
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5622
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.