hi guys ... there is a problem .. i dont know how to maintain my OOP structure while programming in Windows Forms (C# mostly) .. I usually end up coding everything in Form1.cs file .. while my Program.cs file usually contains the code generated by Visual studio.. Can someone please tell me that what would be the correct way to program in Windows Forms.. I want to write Professional Apps .. Any help is appreciated // Examples would be great ..
Thankyou in advance.
Regards ,
Mohsin.
Suitable way to program with WinForms
Started by sp3tsnaz, Dec 04 2009 12:38 AM
4 replies to this topic
#1
Posted 04 December 2009 - 12:38 AM
|
|
|
#2
Posted 04 December 2009 - 02:04 AM
Well, write classes to do stuff that you would normally code in and run in your Form.cs file. The best approach is that you form should know nothing about things like database connection string, and also should know nothing about hot the data is retreived. All the code in your Form class should be ina way generic.
Also use classes, class libraries and stuff to make things reusable.
This is only long story short, because I don't really have time at the moment to post some example code. Maybe later.
My advice is to get some book that explains windows form programming (C# Step by Step, Pro C# and .NET platform 3.5,....).
Also use classes, class libraries and stuff to make things reusable.
This is only long story short, because I don't really have time at the moment to post some example code. Maybe later.
My advice is to get some book that explains windows form programming (C# Step by Step, Pro C# and .NET platform 3.5,....).
#3
Posted 04 December 2009 - 02:05 AM
oh thankyou for the books and tips .. i ll start looking into that (Y) thanks
#4
Posted 05 December 2009 - 09:49 AM
I am currently messing around with the same professional concept with some side projects. Here is my theory and practice going into it...
I have created classes for various 'categories' of my app that houses the data relevant to that 'category'. For example, a Project class that verifies the project is good. I will be using the value stored in projectID for EVERYTHING in my app, so according to a previous posting..
http://forum.codecal...ic-get-set.html
I have decided to get/set the projectID value from the user in the program.cs so i don't have to keep 'manipulating' or making the value 'jump around'.
Now, i'm working on a LoadData class. This houses the queries i need to run, gets/sets various frequently used variables and returns it to Form1.cs.
In Form1.cs i try to keep it at a minimum. I call my events, instantiate necessary objects to call the other classes to run/calculate/do stuff with my data, and report back that data to Form1.cs where it will use the data returned to populate a dropdown(or w/e the case may be).
I have an InputBox that asks the user to enter their ProjectID. I believe it's best to put the validate the data entered on the button click event from this InputBox(new form) rather than inside the Form1 where the user hit 'file - new'. I'm not sure the industry preferred method.. but it seems right to me.
I hope i made any sense... :-)
I have created classes for various 'categories' of my app that houses the data relevant to that 'category'. For example, a Project class that verifies the project is good. I will be using the value stored in projectID for EVERYTHING in my app, so according to a previous posting..
http://forum.codecal...ic-get-set.html
I have decided to get/set the projectID value from the user in the program.cs so i don't have to keep 'manipulating' or making the value 'jump around'.
Now, i'm working on a LoadData class. This houses the queries i need to run, gets/sets various frequently used variables and returns it to Form1.cs.
In Form1.cs i try to keep it at a minimum. I call my events, instantiate necessary objects to call the other classes to run/calculate/do stuff with my data, and report back that data to Form1.cs where it will use the data returned to populate a dropdown(or w/e the case may be).
I have an InputBox that asks the user to enter their ProjectID. I believe it's best to put the validate the data entered on the button click event from this InputBox(new form) rather than inside the Form1 where the user hit 'file - new'. I'm not sure the industry preferred method.. but it seems right to me.
I hope i made any sense... :-)
CodeMonkey +15 | CommunicationSkills -34 | ClarityUsingEnglish -55 | Clarity while pointing at the monitor and making vigorous facial expressions, occasional grunts, and mouth clicks +150
#5
Posted 05 December 2009 - 10:14 AM
That's just the way it is supposed to be done. Group similar things together in its own class, write a code that can be reused and as much generic as possible.
And keep in mind that your Form class is not supposed to know anything about connection string, sql queries and so on. Form should be just a tool that interacts with user (reads input from text boxes, combo boxes, etc... calls methods in different classes to do stuff with this input data and shows modified data back to user.
And keep in mind that your Form class is not supposed to know anything about connection string, sql queries and so on. Form should be just a tool that interacts with user (reads input from text boxes, combo boxes, etc... calls methods in different classes to do stuff with this input data and shows modified data back to user.


Sign In
Create Account


Back to top









