dushi,
I am not sure, but here is what I am understanding based on your code... When a user clicks on "SAVE" in your Menu tool, you want a new form to appear with a textbox and a "OK" button. The user types in their name in the textbox and presses "OK". When "OK" is pressed that new form should close and a message box appears and says "Hello Mary" (assuming Mary is what was typed in the textbox).
If this is correct, the easiest way to do it would be to use an InputBox control. Something like this:
CODE
Private Sub SaveToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveToolStripMenuItem.Click
Dim strName As String
strName = InputBox("Please type your name")
MsgBox("Hello " & strName)
End Sub
Alternately, if you want to do this the hard way, well, more power to you! Here are a couple things to consider.
When you created the second form, your code was "Dim f2 As New Form2". This will not work unless you already have another form in your project called Form2.
In your form, you did not provide any properties for the textbox...size, location, which form it is supposed to be displayed on.
I'd recommend that you create a new form, a textbox (for user input), a label (to prompt users), and 2 buttons (OK and Cancel). Here's how I would do it:
CODE
Private Sub SaveToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveToolStripMenuItem.Click
Dim f2 As New Form
Dim TextBox1 As New TextBox
Dim LabelUserName As New Label
Dim ButtonOK As New Button
Dim ButtonCancel As New Button
With f2
.MinimizeBox = False
.MaximizeBox = False
.AutoSizeMode = Windows.Forms.AutoSizeMode.GrowAndShrink
.AutoSize = True
End With
With LabelUserName
.Parent = f2
.Left = 5
.Top = 5
.Width = 117
.Height = 13
.Text = "Please type your name:"
End With
With TextBox1
.Parent = f2
.Left = 5
.Top = 18
.Width = 156
.Height = 20
End With
With ButtonOK
.Parent = f2
.Left = 14
.Top = 68
.Width = 75
.Height = 23
.Text = "OK"
.DialogResult = DialogResult.OK
End With
With ButtonCancel
.Parent = f2
.Left = 95
.Top = 68
.Width = 75
.Height = 23
.Text = "Cancel"
.DialogResult = DialogResult.Cancel
End With
f2.ShowDialog()
If f2.DialogResult = Windows.Forms.DialogResult.OK Then
MessageBox.Show("Hello " & TextBox1.Text)
End If
End Sub
Finally, since the code sample you posted is contained in a Sub called "SaveToolStripMenuItem_Click" I am assuming that rather than really wanting a MessageBox to display the person's name, you are really trying to use a new form to get a directory or path where the user wants to save a file to. If this is the case, I would recommend using "SaveFileDialog". This will allow the user to browse for a location where they want to save the file. You will still have to provide the code to save the file to that location though.
CODE
Private Sub SaveToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveToolStripMenuItem.Click
Dim f2 As New SaveFileDialog
Dim dr As DialogResult = f2.ShowDialog
If dr = DialogResult.OK Then
MsgBox(f2.FileName)
End If
End Sub
I hope this post help you out!
-Rob