|
-
Aug 23rd, 2007, 10:11 AM
#1
Thread Starter
Fanatic Member
[RESOLVED] [02/03] Is there anything inherently wrong with this?
Public Class Form1
Inherits System.Windows.Forms.Form
Private Sub TextBox_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs)
If e.KeyData = Keys.Enter Then
Me.TextBox1.Text = DirectCast(sender, TextBox).Text
DirectCast(DirectCast(sender, TextBox).Parent, Form).Close()
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim f As New Form2
AddHandler f.TextBox1.KeyDown, AddressOf TextBox_KeyDown
f.Show()
End Sub
End Class
So, I have two forms, each with a textbox. Form1 has a button which launches Form2. Form1 adds an event handler to the textbox in Form2 so that when you press Enter, it grabs the text and closes Form2. Is this OK to do? I mean, in my little test, it works. But, is this really bad practice?
Also, I cannot use ShowDialog().
VB.Net 2008
.Net Framework 2.0
"Must you breathe? 'Cause I need heaven..."
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
|