Please, I think it isn't a big deal, but still I am having problems because I am a beginner.
Can someone write me a code that will do next: I want my text from textbox wich I enter in a dialogbox to enter itself into textbox in my form when I click OK. I hope my post isn't too much unclear!
Your post is perfectly clear: You want someone to do your work (or, more likely, your homework) for you.
Have you tried doing this yourself yet? If so, can you share your code and what you think the problem is as to why it doesn't work? If you haven't tried to do this yourself yet, why not? How do you expect to learn if you don't at least try?
Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click
Me.DialogResult = System.Windows.Forms.DialogResult.OK
Me.Close()
Form1.Enabled = True
And look:
Form1.TextBox1.Text = TextBox1.Text
You are assigning the text of the textbox to itself. This won't change anything.
First you have to get the input from the dialog to a string variable like strText
(Possibly that's your line Me.DialogResult = System.Windows.Forms.DialogResult.OK
Then you assign the string to the textbox like Form1.TextBox1.Text = Me.DialogResult
Then you may do Me.Close. When you close the form, the contents of its variables get lost.
However I'm not quite sure how the VB.NET Dialog works.
What SHOULD happen?
You need to test IF OK was pressed, then commence with adding the text in the textboxes.
ALso, you cannot Close the dialog box. By closing it, you dispose of it - that means you wipe the memory clear, so, in fact, there is NO text to bring over to the form.
Form.Enabled - is very bad practise. You should show the form.
Is so CONFUSING. This is the problem when people do not learn how to properly name objects! I would suggest you give each form and each object on the form(s) proper names! It confuses everyone. I think that you have two improperly named forms, then on each form, you have textboxes named TextBox1 and TextBox2. Change that.
And look:
Form1.TextBox1.Text = TextBox1.Text
You are assigning the text of the textbox to itself. This won't change anything.
I thought the same thing at first glance but after reading again I saw that these are textboxes on 2 different forms. Apparently the intention was that the code shown is intended to be the dialog form and is to return values to the calling form which of course should be handled much differently.
Calling form
Code:
Dim frmTemp As New frmDialog
frmTemp.ShowDialog()
If frmTemp.DialogResult = Windows.Forms.DialogResult.OK Then
textbox1.text = frmTemp.textbox1.text
textbox2.text = frmTemp.textbox2.text
End If
frmTemp.Close()
Ok. I have not tried either because it is VB.Net. In VB6 we do not have Me.Close, but we have Unload Me and I'm sure that this will loose the contents of any variable local to that form.
Ok. I have not tried either because it is VB.Net. In VB6 we do not have Me.Close, but we have Unload Me and I'm sure that this will loose the contents of any variable local to that form.
I think this was missed somewhow
Originally Posted by HanneSThEGreaT
ALso, you cannot Close the dialog box. By closing it, you dispose of it - that means you wipe the memory clear, so, in fact, there is NO text to bring over to the form.
Bookmarks