Organising UI code in .NET forms

Posted by sb3700 on Stack Overflow See other posts from Stack Overflow or by sb3700
Published on 2010-06-16T09:44:44Z Indexed on 2010/06/16 10:02 UTC
Read the original article Hit count: 216

Filed under:
|
|

Hi

I'm someone who has taught myself programming, and haven't had any formal training in .NET programming.

A while back, I started C# in order to develop a GUI program to control sensors, and the project has blossomed. I was just wondering how best to organise the code, particularly UI code, in my forms.

My forms currently are a mess, or at least seem a mess to me.

  • I have a constructor which initialises all the parameters and creates events.
  • I have a giant State property, which updates the Enabled state of all my form control as users progress through the application (ie: disconnected, connected, setup, scanning) controlled by a States enum.
  • I have 3-10 private variables accessed through properties, some of which have side-effects in changing the values of form elements.
  • I have a lot of "UpdateXXX" functions to handle UI elements that depend on other UI elements - ie: if a sensor is changed, then change the baud rate drop down list. They are separated into regions
  • I have a lot of events calling these Update functions
  • I have a background worker which does all the scanning and analysis.

My problem is this seems like a mess, particularly the State property, and is getting unmaintainable. Also, my application logic code and UI code are in the same file and to some degree, intermingled which seems wrong and means I need to do a lot of scrolling to find what I need.

How do you structure your .net forms?

Thanks

© Stack Overflow or respective owner

Related posts about .NET

Related posts about winforms