Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Visual Basic .NET (http://www.programmingforums.org/forum19.html)
-   -   Design Question (http://www.programmingforums.org/showthread.php?t=13541)

NightShade01 Jul 12th, 2007 11:01 PM

Design Question
 
This might sound like a really newbie question but I figure it really has an impact on the runtime and speed of applications so I wanted an opinion. Suppose you create a project that contains a screen for the main page, sending in emails, an information page, and an about page. Would it be better design wise to create seperate forms for each one and then hide/show each as needed or would it be better to make one form with controls that can be created within the main page for email, information, and about information. I guess what i'm asking is what is the benefit to hand coding controls, and specifics when visual studio can just as easily create individual forms and show them as needed.

Also as a side note when i run apps with multiple windows and click to change between forms the taskbar always shows one form hiding and a new form appearing (kinda of like opening a new form everytime). How can you make it so that this "effect" doesn't occur.

john Wesley Jul 13th, 2007 1:40 PM

To tackle your last query first - if I have a grasp of what your talking about, but it all depends how you handle this behaviour within your application along with Windows settings. For instance, the number of these taskbar tabs that will be grouped is relevant to a Windows setting however your problem lies with the way your using forms, from what I imagine.

If a form is loaded and displayed, then depending on your property settings it will have a tab in the taskbar, hiding it will then remove the tab and I presume your hiding one form to show another hence the 'effect', on the other hand you may not be hiding the other form in which case my advice is to detect the form and bring it forward instead of displaying it again.

Loading all forms at run-time to hide\show as and when is really quite insane unless you have a reason other than one which is to display interfaces faster. You should strive to write code in such a manner that executing the code units to initialise and display a form is efficient as possible and not rely on a users memory.

The benefits of controls can be used to implement full-featured forms, but generally used to write elemental feature's which can be used widely accross the application, and even to be exposed to calling applications, such as a login dialog for a database for example. Another example is a custom control I had to write for a client this week, which was a folder browser control, this control is to be shown in mutliple places as its own dialog but in one circumstance it acts as a toolbar in an MDI container.

So for non-standard circumstances, including times where you are required to draw your own control, which is another good reason for custom controls, then do so, otherwise dont go through the effort, IMO.

NightShade01 Jul 14th, 2007 5:20 PM

Thanks for the info it makes more sense now. I have a follow up question though. Suppose I have the same application with 4 different forms. Each form has a "next" button that "shows" the next form. When i run the comlied .exe file it only shows one instance of the program however like you were saying all the forms are loaded, because if they weren't i wouldn't be able to "show" them i would have to create an instance of them first. How do i then get just the main form to load when the exe starts this way when i hit "next" i can create an instance of the forms i want and dispose of them when i'm done.

bigguy Jul 14th, 2007 5:45 PM

On your main form_load do you habe like
form1.show
form2.show
form3.show
form4.show

Cause that could cause it. I made a small program just now and compiled and done like you said, only showing the form when clicking next. It worked, all the forms didnt show up on startup. They only showed up when I hit Next.

This kind of what you looking for?

john Wesley Jul 14th, 2007 6:04 PM

Yes, its simple, just dont instatiate the forms on initial execution of your program but do it within the 'next' buttons click event.

If you need to remember the state of specific elements on the form between switches, use settings to store and retrieve the relevant values etc.

NightShade01 Jul 15th, 2007 12:41 AM

@bigguy yeah I have something simliar to that...
@john How would I not instantiate them? I have two forms the main form has one button that says next. The other form just has a label on it. When the main form loads and you click next the code reads:

form2.show()

Which it does and only one instance of it (no matter how many times you hit next). which leads me to beleive that like you were saying originally all forms are being loaded at startup. btw thanks for all the help on this

john Wesley Jul 15th, 2007 9:20 AM

NightShade01,

Just got up and read your post but give me a little time, simply because I have not used VB.NET for a while and would not want to give you false information, if you wait until I get back and fire up VS il let you know.

john Wesley Jul 15th, 2007 1:18 PM

Yes it is just as I thought, I simply needed to double check VB.NET gave control over this matter...

Create a new instance of a and show as below:

:

    Dim CurrentForm As New TheForm()
    CurrentForm.Show()


Then you can just dispose of the object as neccesary, or the GC will clean it up if you neglect to do so.


All times are GMT -5. The time now is 2:49 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC