Results 1 to 10 of 10

Thread: simple question - Form progression

  1. #1

    Thread Starter
    Fanatic Member staticbob's Avatar
    Join Date
    Jan 2005
    Location
    Manchestershire, UK Cabbage: I do
    Posts
    619

    simple question - Form progression

    Guys,

    I am developing an app in VB.NET, I'm pretty new to this so be gentle.

    I have a "homepage" for the app, this has a series of 7 buttons on that progress to a similar screen for the section clicked. Each of the sectional forms have more buttons on, each relating to a specific task.

    I am opening the new forms on button click with this code . .

    Code:
        
        Private Sub btn_procurement_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_procurement.Click
            Dim frm_procurement As New frm_procurement
            frm_procurement.ShowDialog()
        End Sub
    Should I be closing frm_homepage when the users navigate to the new form ? If so, how. I notice that each open form shows as a new item on the taskbar.

    Thanks
    Bob

  2. #2
    Hyperactive Member Lil Ms Squirrel's Avatar
    Join Date
    Nov 2004
    Location
    planet squirrel
    Posts
    494

    Re: simple question - Form progression

    Forms have a ShowInTaskbar property which you should set to false for each of the child forms you are opening.
    Be who you are and say what you feel, because those who mind don't matter and those who matter don't mind.
    Dr. Seuss

  3. #3

    Thread Starter
    Fanatic Member staticbob's Avatar
    Join Date
    Jan 2005
    Location
    Manchestershire, UK Cabbage: I do
    Posts
    619

    Re: simple question - Form progression

    Thanks Squirrel

    I have a back button on each form with me.close assigned on click.

    I also need a "Home" button, that will close all other forms and return to the homepage ???

    Thanks
    Bob

  4. #4
    Hyperactive Member Lil Ms Squirrel's Avatar
    Join Date
    Nov 2004
    Location
    planet squirrel
    Posts
    494

    Re: simple question - Form progression

    Try this:

    1, Create a class module called forms collection and add this code:

    VB Code:
    1. Public Class FormsCollection
    2.     Inherits System.Collections.CollectionBase
    3.  
    4.     Public Sub Add(ByVal formToAdd As Form)
    5.         MyBase.InnerList.Add(formToAdd)
    6.     End Sub
    7.  
    8.     Public Sub Remove(ByVal formToRemove As Form)
    9.         MyBase.InnerList.Remove(formToRemove)
    10.     End Sub
    11. End Class

    2, Create a module containing the following line of code:

    VB Code:
    1. Public forms As New FormsCollection

    3, In the "Create new form" button's click event handler add something like this:
    VB Code:
    1. Dim newForm As New Form1
    2.         forms.Add(newForm)
    3.         newForm.Show()

    4, Finally in the "Home" button's click event on the child form, add the following:

    VB Code:
    1. Dim frm As Form
    2.         For Each frm In forms
    3.             frm.Close()
    4.         Next
    5.         forms = Nothing
    6.         forms = New FormsCollection

    It's a bit rough and ready as far as coding goes, but it should get you started...
    Be who you are and say what you feel, because those who mind don't matter and those who matter don't mind.
    Dr. Seuss

  5. #5
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949

    Re: simple question - Form progression

    Hi,

    I'm a bit dumb on this type of approach so I'm probably missing something but doesn't that code simply create several instances of the same form?

    If it does create instances of different forms, how do you refer to each form if you want to access it from another?
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  6. #6
    Hyperactive Member Lil Ms Squirrel's Avatar
    Join Date
    Nov 2004
    Location
    planet squirrel
    Posts
    494

    Re: simple question - Form progression

    This code was taken from a forms collection that I use to create multiple instances of a form. For example, the application allows several customer records to be opened at once, but only one instance of every customer. So the full version has a method that allows you to check the object stored in each form's tag property.

    When I open a customer record, I store the datarow from the dataset (or you could store just the customer's id) in the tag property. Then, I have a method in the forms collection called IsInstanceInCollection which goes something like this:

    VB Code:
    1. Public Function IsInstanceInCollection(ByVal formName As String, ByVal row As DataRow) As Form
    2.         Dim item As Form
    3.         Dim formRow As DataRow
    4.         Dim counter As Integer
    5.         Try
    6.             'loop through the forms collection
    7.             For Each item In list
    8.                 If item.Name.ToLower = formName.ToLower Then
    9.                     'if the form names match then retrieve the row
    10.                     formRow = CType(item.Tag, DataRow)
    11.                     'if the items in the left most columns match then return the form as the correct item
    12.                     If formRow(0) = row(0) Then
    13.                         Return item
    14.                     End If
    15.                 End If
    16.             Next
    17.         Catch ex As Exception
    18.             MessageBox.Show("Error locating the specified instance of " & formName)
    19.             Return Nothing
    20.         Finally
    21.             formRow = Nothing
    22.             item = Nothing
    23.         End Try
    24.     End Function

    This returns the instance of the form if found.

    The calling code is an If statement that checks to see if the method returns something and if not, will create a new instance to display to the user and stores the relevant data row in the tag property as the new form is loaded.

    It is overloaded to work in a variety of different ways.

    A cut down version of this to work with the code that staticbob wrote would go something like this:

    VB Code:
    1. Public Sub Remove(ByVal formTagObject As Object)
    2.         Dim frm As Form
    3.         For Each frm In MyBase.InnerList
    4.             If frm.Tag = formTagObject Then
    5.                 MyBase.InnerList.Remove(frm)
    6.                 Exit For
    7.             End If
    8.         Next
    9.     End Sub

    To use this, I just created a unique string to store in each new form's tag object when instantiating and adding them to the collection.

    Hope this clarifies things
    Be who you are and say what you feel, because those who mind don't matter and those who matter don't mind.
    Dr. Seuss

  7. #7
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949

    Re: simple question - Form progression

    Hi,

    Thanks, that's what I thought. But this guy wants to open one instance each of several different forms.
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  8. #8
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949

    Re: simple question - Form progression

    Hi staticbob,

    What you have to do depends on how you start your programme. Please confirm or deny the following: (I am using the word "Open" loosely, in it's VB6 sense. meaning that whilst Open an instance of a form is still available even though hidden)

    1. HomePage is the Startup form or

    2. A. You start from the Module Sub Main
    B. You want HomePage to remain open throughout the programme
    (although you may want it hidden or behind the other forms) - this is
    normal except for splash type forms.

    3. You want your other forms to be opened from HomePage and sometimes to
    remain open when the focus moves to HomePage but at other times to
    close.

    4. You sometimes want to close all open other forms and leave only
    HomePage open.

    I am going out for the rest of the day so I will not be able to reply quickly. Others might.

    Best of luck.
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  9. #9
    Hyperactive Member Lil Ms Squirrel's Avatar
    Join Date
    Nov 2004
    Location
    planet squirrel
    Posts
    494

    Re: simple question - Form progression

    The other thing I noticed from the original post is that it's using ShowDialog which won't work by launching multiple forms from the home page. I would imagine you are using Show Staticbob?
    Be who you are and say what you feel, because those who mind don't matter and those who matter don't mind.
    Dr. Seuss

  10. #10
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949

    Re: simple question - Form progression

    Quote Originally Posted by Lil Ms Squirrel
    The other thing I noticed from the original post is that it's using ShowDialog which won't work by launching multiple forms from the home page. I would imagine you are using Show Staticbob?

    It depends what he wants to do. Yes, he will have to close them but he can still keep the instance if he wants to, ready to show again.
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width