1

I'm refactoring an existing VB.net application that is ~6,000 lines in one file, and I've encountered a dilemma.

  • On the one hand, I can use visual studio's Data Sources and drag-and-drop functionality to get rid of all the hand-written code that sets up the DataAdapters, DataSets, DataTables, CurrencyManagers and the manually linking between them all.

  • On the other hand, I can separate the logical pieces of my UI into User Controls.

Now, if I only do the first one, I end up with tons of controls all in the same form, which causes me to have tons of controls in the same 'namespace' that I have to manage, and forces me to write all custom UI logic and event handling in the code behind for the single main form.

If I only do the second one, I get the distinct visual pieces of my UI in separate files, which gives me an appropriate place to write specific event handling and formatting code; but it doesn't let me use the visual studio designer to hook my dynamic components (e.g. DataGridViews) up to the BindingSources in the parent form. The nice thing about this is that I get to set the myriad properties (column width, read-only etc.) in the GUI, which seems like it would make the project much more maintainable.

What's the sensible course of action here? Or is there some possible way to employ both tactics (which is what I would ideally like to do)? I'm definitely looking for some guidance here - I'm a complete vb.net newbie.

Thanks!

Sam Selikoff
  • 12,366
  • 13
  • 58
  • 104
  • 1
    Where I work we use the MVP pattern when building winforms apps and find it very effective. It would take a while to describe it here, but have you checked out this post: http://stackoverflow.com/questions/4794121/model-view-presenter-in-winforms should be helpful. – majjam Nov 19 '13 at 23:34
  • My vote is for option 1 - and if there's 'tons' of controls in a 'single main form' consider re-working the GUI to use multiple simpler forms. – peterG Nov 19 '13 at 23:35
  • thanks K@bamie9l. @peterG the only way I've seen multiple forms used is with dialogues, is there another way? Something more similar to how a website may have multiple pages? – Sam Selikoff Nov 20 '13 at 00:50
  • It just seems so strange to me that there isn't a better way to encapsulate UI logic. I feel like I'm missing something. – Sam Selikoff Nov 20 '13 at 01:09
  • Well a familiar way to design an application is say have one form with a grid listing customers; dbl-click a customers row in the grid and a customer editor form opens, which might also display a list of orders etc etc. – peterG Nov 20 '13 at 02:42
  • But the customer editor form would be a new dialogue right? Or would it replace the customers form? – Sam Selikoff Nov 20 '13 at 03:23
  • 1
    If by 'dialog' you mean 'Modal form' then not necessarily. You can have multiple non-modal forms open, each of which encapsulates its own functionality. So you could eg open multiple customer editor forms for different customers simultaneously. So if the phone rings from customer B while user is already dealing with customer A . . . – peterG Nov 20 '13 at 12:35

0 Answers0