Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
VB.NET 2002/2003 Basics For coders who are new to Visual Basic, working in .NET versions 2002 or 2003 (1.0 and 1.1).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET 2002/2003 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old June 8th, 2005, 08:23 AM
Authorized User
 
Join Date: May 2005
Location: Berlin, CT, USA.
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default General Scoping Question

Hi all:

I have a general question concerning scoping of code within an application.

I have written an application that consists of a main (parent) form with a toolbar that shows several additional (child) forms based on the value selected on the toolbar.

I have noticed that each of the child forms share identical or nearly identical event handlers like the form load handler, the form close handler, and various common button click event handlers (for exporting to excel, or printing, or initiating a database query etc).

Is there a way to place/define this common code so that it is not replicated amongst each of the forms?

It would be great if these common elements could be defined once in the overall project and not have to be in each form.

Thanks in advance for any suggestions.


  #2 (permalink)  
Old June 8th, 2005, 10:21 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , .
Posts: 540
Thanks: 0
Thanked 4 Times in 4 Posts
Default

Every instance of a standard windows form is going to contain the same event handlers.

If the forms are so similar that you would use the same code in the event handlers for each of them, why don't you just use one form for everything and perform actions based upon what the user selects?

If this isn't what you want, you probably want to develop classes to utilize common methods and properties for your application (or to be used among multiple applications).

J
  #3 (permalink)  
Old June 9th, 2005, 06:37 AM
Authorized User
 
Join Date: May 2005
Location: Berlin, CT, USA.
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by katsarosj
 Every instance of a standard windows form is going to contain the same event handlers.

If the forms are so similar that you would use the same code in the event handlers for each of them, why don't you just use one form for everything and perform actions based upon what the user selects?

If this isn't what you want, you probably want to develop classes to utilize common methods and properties for your application (or to be used among multiple applications).

J
The forms themselves are not identical, it's just certain controls and certain event handlers end up the same. For example, on each form, there is a submit button to submit a query, a print button to print the datagrid, and a button to export the dataset to excel. The load and closing handlers for the forms are all identical.

In addition, each form has additional specific controls that are unique to that form. I guess the approach I could take is to make a generic form with all the common controls, and have each subsequent specific form use that generic query form as a base to inherit all the common properties. Perhaps I will give that a whirl.





Similar Threads
Thread Thread Starter Forum Replies Last Post
General Question about the beerhouse example kss BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 1 November 26th, 2008 12:08 PM
General SELECT question rsearing SQL Server 2005 1 January 16th, 2007 12:01 PM
General Question About c++ madeebmir C++ Programming 0 August 15th, 2006 10:48 AM
Very general question merianos VB How-To 4 August 1st, 2006 12:24 PM
General Question stu9820 ASP.NET 1.0 and 1.1 Basics 2 September 23rd, 2003 03:36 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.