Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / February 2007

Tip: Looking for answers? Try searching our database.

Calling a function from another form

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Kevin Humphreys - 02 Feb 2007 17:29 GMT
Hi There,
I have 2 forms and I need to execute a subroutine on formA from FormB
passing specific parameters. Can this be done using VB.NET?
I would prefer not to use a global function. Just something local to 2
forms.

Thanks,
Kevin.
Tim Mackey - 02 Feb 2007 18:26 GMT
hi kevin,
since the forms are objects, it is a simple matter of ObjectB having a
reference to ObjectA, which can be done with any object-oriented programming
language. In other words, you need a variable of type ObjectA contained in
Object B, initialised to the instance of ObjectA that you want to invoke the
method on.

in depends on which way your forms are created, but you need to ensure that
ObjectB contains a correctly initialised variable for ObjectA.

if you need help setting it up, post the code that you use to create both
the forms (and your main() code if either A or B are your main form).  here
is some pseudo code anyway:

function main()
   dim form1Object as new form1()    'create a form1
   dim form2Object as new form2()    'create a form2, but don't show it yet
   form1Object.Form2Reference = form2Object    'set the reference to
form2Object
   form1Object.showdialog()
   'now inside form1 you can do things like:
me.Form2Reference.whatever(whatever)
end function

your form 2 should look like this:

class form2
   ..... other variables here etc
   public form2 Form2Reference

end class

there are some design patterns like Model View Controller which have a
technique for achieving this.

hope this helps
tim

> Hi There,
> I have 2 forms and I need to execute a subroutine on formA from FormB
[quoted text clipped - 4 lines]
> Thanks,
> Kevin.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.