tags:

views:

40

answers:

2

Hi guys,

I have two projects in a solution: GUI and Controls.

Controls is supposed to have our company's custom controls, and all the forms live in the GUI. However back in the dark times before the Empire, some genius thought it would be a great idea to create a TextBoxLookup control. This has a custom property you can set (eg BankAccount) and a textbox with a button on the right. When you click on the button, it goes through a case statement and brings up the appropriate form, eg

select Case Me.LookupField
   .
   .
   .
Case FieldsEnum.BankAccount
   Dim x as new frmBankAccountLookup
   x.ShowDialog
Case FieldsEnum...
   .
   .
   .
End Select

Over time, this led to about 20 forms (that belong in the GUI) actually being crammed in the Controls project just so they can be referenced!

The GUI references the Controls project and has the textbox on the screen. I'm trying to clean this up and get them back in the GUI where they belong. When the button is pressed, how can I flick the Me.LookupField property back to the GUI project and have it bring up the form? Delegates? Events? Base forms? The lookup control is being used in zillions of forms so eliminating it is out...

+2  A: 

It would be much nicer if the control raised an event to inform which item has been selected. Then the form containing the control can respond to the event and display the appropriate form. This should allow you to separate your controls from knowing about other forms.

Mark
A: 

You need to separate the design of the control and the actual logic.

Have the control simply fire an event that the user has clicked the button, and then handle it in the GUI project (where you create the instance of the control).

This way you will be able to attach any functionality to the control and easily reuse it in other projects.

Groo