To open a new window in vb by clicking a button replacing the previus windw

You can't (easily) replace it, but you can hide the current window and call tne new window's ShowDialog().

First, you have to unload or hide the current window (where you will click the button) then show the window that you want to show using it's name.

On the button which will show the next form.

VB 6:

Private Sub Command1_Click()

Me.Hide
Form2.Show()

End Sub

VB 2008:

Public Class Form1

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

        Me.Hide()   // this will hide the window where this code is entered
        Form2.Show() //this will display the other window, Form2 is the name,replace it with yours, you can also use Form2.ShowDialog() 

    End Sub
End Class

Haven't tried VB 2010. :-)

got it . thanks :)

just a small corection .

 Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 
Dim A as Form2()     // make the new form to a variable 
Me.Hide()   // this will hide the window where this code is entered
A.Show()     //this will display the other window, Form2 is the name,replace it with yours, you can also use Form2.ShowDialog() 
End Sub
End Class

@killer88,

It seems you were looking for vb.net code, which is a different forum from vb6. :) Irrespective, it seems that your problem was solved, please mark as such, thanx.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.