Question closing previous window when new window opens

razz

Well-known member
Joined
Oct 11, 2008
Messages
67
Programming Experience
Beginner
I am very new to VB.Net and am using Visual Basic 2008 Express Edition.
I have 2 questions:

(1) For any posts in the future, is Visual Basic 2008 Express usually referred to as VB Studio 2008?

(2) I have written a program and wish to close previous window when the new window opens. What code would I need to use to accomplish this?

Example:

Public Class MainPanel

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
PerformDaily.Show()


As you know...this opens form "PerfrormDaily", but form "MainPanel" remains open.

Thank you for your help.
 
1) VB 2008, VB 08

2) You have basically 2 options you can hide MainPanel -- Me.Hide() or you can actually close the window -- Me.Close()

You will need to decided which is better for your program. Do you switch back and forth between forms? Will you need to 'reset' the variables, properties, etc... when you move to the new? Are you using an MDI or SDI application (Multiple Document Interface or Single Document Interface) ? By no means is this a complete list of things to consider when opening and closing forms.
 
2) You have basically 2 options you can hide MainPanel -- Me.Hide() or you can actually close the window -- Me.Close()

You will need to decided which is better for your program. Do you switch back and forth between forms? Will you need to 'reset' the variables, properties, etc... when you move to the new? Are you using an MDI or SDI application (Multiple Document Interface or Single Document Interface) ? By no means is this a complete list of things to consider when opening and closing forms.
My program opens with main panel showing. I want the main panel window to close when the user clicks one of the button options. The user will then often need to go back to the main panel after they're finished with present window. I would provide a "back to main panel" button on each of my other windows.

What code would be best in this case? demausdauth, thanks for your time!!
 
It sounds as though .Hide() would be your best bet. You can hide Main form when you want the other forms to show and then when you 'go back' you just .Show() the main form.
 
Geez! I love your super prompt reply. Thank you. I have one more question (hope you don't mind) on another hick-up within the same program. If you want me to make a new post just let me know.

I can change color on all forms except on 4 of them.
I used the same code in all cases and cannot figure out what the problem is.

My code is:

Private Sub Button4_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Button4.Click
ColorDialog1.ShowDialog()
Me.BackColor = ColorDialog1.Color
End Sub

The only difference between the forms that work and the 4 that do not is
the 4 forms were created within the TabControl.

Any help will be greatly appreciated.
 
By 'created within the TabControl' are you saying that they are TabPages? if so then you would need to set the TabPage's BackColor, not the Form's back color.
 
I used the "ColorDialog" tool to allow the user to define customized colors. The 'Change Color" button I created on all pages works great, except on the 4 pages that were created as tab pages (i.e. created using the "TabControl" tool).
 
Ok, so you have a Form (frmTabForm) with a TabControl on it (tbcTabs) and it has 4 TabPages (tbp1, tbp2, tbp3, tbp4).

VB.NET:
Private Sub Button4_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Button4.Click
ColorDialog1.ShowDialog()
Me.BackColor = ColorDialog1.Color
'This will set the current form back color 
' essentially it is saying frmTabForms.BackColor = ColorDialog1.color
' I think what you want is 
' tbp1.BackColor = ColorDialog1.Color
' To use the control names from my example above.
End Sub

Does this sound more like what is going on?
 
Based on what you said, I tried:
Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
ColorDialog1.ShowDialog()
tbp1.BackColor = ColorDialog1.Color

End Sub
End Class


An error message states the following:
Name 'tbp1' is not declared.

I guess I have done something wrong.

The other code you gave me works great (closing window). Thanks!
 
tbp1 was my example name for a TabPage within the TabControl. if you have not renamed any of the TabPages that you have added, then they are probably TabPage1, TabPage2, TabPage3, TabPage4.

Incidentally when in the designer, if you click on the TabControl then click on the first TabPage and right click then select the properties. when the properties come up if you look at the 'Name' property that is your tab page.

if this doesn't help -- then could you post the code for the whole form?
 
demausdauth, you're a programming genius!! It worked like a charm (as soon as I got it through my head exactly what you meant). Now I feel dumb :-(
Thank you for all your help. Cheers!
 
Back
Top