Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

button on a dynamic form

Status
Not open for further replies.

Yogeetarp

Programmer
Jun 7, 2006
10
0
0
US
Hello,

I am creating a form dynamically based on some button click from the original form.

Now when I hit exit I want close the current form (dynamically created one), but not the orignial form:

This code is closing both the forms

Dim NewCase As New Form
Dim btnExitCase As Button = New Button

NewCase.Controls.Add(btnExitCase)

With btnExitCase
.Text = "Exit"
.Location = New Point(725, 100)
.Size = New Size(75, 25)
End With
AddHandler btnExitCase.Click, AddressOf btnExitCase_Click

Private Sub btnExitCase_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Me.Close()
End Sub

The Me.close is the one posing problem, but how else can i say close the NewCase form only.

Any help or suggestions would be appreciated.
Thanks
 
Does this mean I have to declare the Form as a global field?
 
I am looking at Chrissie1's reply where he changes the
Me.Close() to newcase.Close().

When I entered the same code in my project, I got an error that newcase was not declared. As I look at the code in the thread, I am wondering how you can use "newcase.Close()" in the Private Sub btnExitCase subroutine if you never had declared newcase within that subroutine?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top