|
-
Feb 1st, 2005, 06:56 AM
#1
Thread Starter
Fanatic Member
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
-
Feb 1st, 2005, 08:29 AM
#2
Hyperactive Member
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 
-
Feb 1st, 2005, 09:36 AM
#3
Thread Starter
Fanatic Member
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
-
Feb 1st, 2005, 10:35 AM
#4
Hyperactive Member
Re: simple question - Form progression
Try this:
1, Create a class module called forms collection and add this code:
VB Code:
Public Class FormsCollection
Inherits System.Collections.CollectionBase
Public Sub Add(ByVal formToAdd As Form)
MyBase.InnerList.Add(formToAdd)
End Sub
Public Sub Remove(ByVal formToRemove As Form)
MyBase.InnerList.Remove(formToRemove)
End Sub
End Class
2, Create a module containing the following line of code:
VB Code:
Public forms As New FormsCollection
3, In the "Create new form" button's click event handler add something like this:
VB Code:
Dim newForm As New Form1
forms.Add(newForm)
newForm.Show()
4, Finally in the "Home" button's click event on the child form, add the following:
VB Code:
Dim frm As Form
For Each frm In forms
frm.Close()
Next
forms = Nothing
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 
-
Feb 1st, 2005, 12:21 PM
#5
PowerPoster
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.
-
Feb 2nd, 2005, 03:34 AM
#6
Hyperactive Member
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:
Public Function IsInstanceInCollection(ByVal formName As String, ByVal row As DataRow) As Form
Dim item As Form
Dim formRow As DataRow
Dim counter As Integer
Try
'loop through the forms collection
For Each item In list
If item.Name.ToLower = formName.ToLower Then
'if the form names match then retrieve the row
formRow = CType(item.Tag, DataRow)
'if the items in the left most columns match then return the form as the correct item
If formRow(0) = row(0) Then
Return item
End If
End If
Next
Catch ex As Exception
MessageBox.Show("Error locating the specified instance of " & formName)
Return Nothing
Finally
formRow = Nothing
item = Nothing
End Try
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:
Public Sub Remove(ByVal formTagObject As Object)
Dim frm As Form
For Each frm In MyBase.InnerList
If frm.Tag = formTagObject Then
MyBase.InnerList.Remove(frm)
Exit For
End If
Next
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 
-
Feb 2nd, 2005, 04:03 AM
#7
PowerPoster
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.
-
Feb 2nd, 2005, 04:19 AM
#8
PowerPoster
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.
-
Feb 2nd, 2005, 05:08 AM
#9
Hyperactive Member
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 
-
Feb 2nd, 2005, 05:31 AM
#10
PowerPoster
Re: simple question - Form progression
 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|