-
Sep 5th, 2014, 05:56 PM
#1
Thread Starter
Lively Member
Showing TextBox Text in a Label which is in another Form [Strange Issue]
Hey, i need your help with this simple but strange issue.
In Form1 i have the textbox: Form1.Video_Content1.VideoGame.text
In Form2 i have the label: Game.Text
PHP Code:
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Game.Text = Form1.Video_Content1.VideoGame.Text
End Sub
Now if i change the text of the TextBox (Form1) from the Properties, it's workings, like this:
But if i edit the text after i opened the program, The program simply ignore my edits.
Pleast let me know what do you think.
-
Sep 5th, 2014, 07:52 PM
#2
Lively Member
Re: Showing TextBox Text in a Label which is in another Form [Strange Issue]
hmm.. i misread the code, so i deleted my reply
-
Sep 5th, 2014, 08:02 PM
#3
Lively Member
Re: Showing TextBox Text in a Label which is in another Form [Strange Issue]
ok, im going to guess when you open form2, you are creating a new instance.. and thats why it's ignoring your edits..
if you are creating a new instance (which you dont have to), set the variable of that instance to friend withevents.. dont need the withevents part, but you might later on in development..
so form1 creates new instance:
VB.NET Code:
public class form1 friend withevents gameOverView as new form2 Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load 'code End Sub end class
in form2:
VB.NET Code:
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load gameOverView.Game.Text = Form1.Video_Content1.VideoGame.Text End Sub
or you can just not create a new instance, and then the code as you have it will work..
-
Sep 5th, 2014, 08:03 PM
#4
Re: Showing TextBox Text in a Label which is in another Form [Strange Issue]
Whats Video_Content1? why do you assume form2 even knows about form1? You dont pass it's instance.
-
Sep 5th, 2014, 09:03 PM
#5
Lively Member
Re: Showing TextBox Text in a Label which is in another Form [Strange Issue]
Originally Posted by ident
Whats Video_Content1
im going to be a betting man and say that is a panel or groupbox...
Originally Posted by ident
? why do you assume form2 even knows about form1? You dont pass it's instance.
im going to assume again..
form2 gets opened from form1..
if it is exposed, he shouldnt need to pass it, in order to access it...
-
Sep 5th, 2014, 09:27 PM
#6
Lively Member
Re: Showing TextBox Text in a Label which is in another Form [Strange Issue]
O.o i was looking at this a little backwards.. while this isnt the "best" way, this will work without confusing you..
VB.NET Code:
Public Class Form1 Private Sub OpenForm2(sender As System.Object, e As System.EventArgs) Handles OpenForm2Button.Click Dim gameOverView = New Form2 gameOverView .Show() End Sub End Class
VB.NET Code:
Public Class Form2 Private Sub Form2_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load Me.Game.Text = Form1.Video_Content1.VideoGame.Text End Sub End Class
-
Sep 6th, 2014, 03:43 AM
#7
Thread Starter
Lively Member
Re: Showing TextBox Text in a Label which is in another Form [Strange Issue]
Originally Posted by elielCT
O.o i was looking at this a little backwards.. while this isnt the "best" way, this will work without confusing you..
VB.NET Code:
Public Class Form1
Private Sub OpenForm2(sender As System.Object, e As System.EventArgs) Handles OpenForm2Button.Click
Dim gameOverView = New Form2
gameOverView .Show()
End Sub
End Class
VB.NET Code:
Public Class Form2
Private Sub Form2_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Me.Game.Text = Form1.Video_Content1.VideoGame.Text
End Sub
End Class
First of all thank you very much for trying help, I appreciate it.
I just tried your code and as you can see here i'm getting the same response from the program
Maybe any suggestions will help me a lot.
-
Sep 6th, 2014, 06:23 AM
#8
Re: Showing TextBox Text in a Label which is in another Form [Strange Issue]
Sounds/looks sort of like like an instance issue, where you think you are setting one form but actually setting another / the default instance,
Few way you can try, make a Public string property in form2, set it after creating a new instance of the form.
Or just pass the string in the New instance call, like...
Code:
Public Class Form1
Private Sub OpenForm2Button_Click(sender As System.Object, e As System.EventArgs) Handles OpenForm2Button.Click
Dim gameOverView = New Form2(Me.VideoGame.Text)
gameOverView.Show()
End Sub
End Class
Code:
Public Class Form2
Private Property gameText As String
Public Sub New(game_text As String)
' This call is required by the designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
Me.gameText = game_text
End Sub
Private Sub Form2_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Me.Game.Text = Me.gameText
End Sub
End Class
-
Sep 6th, 2014, 11:34 AM
#9
Thread Starter
Lively Member
Re: Showing TextBox Text in a Label which is in another Form [Strange Issue]
Originally Posted by Edgemeal
Sounds/looks sort of like like an instance issue, where you think you are setting one form but actually setting another / the default instance,
Few way you can try, make a Public string property in form2, set it after creating a new instance of the form.
Or just pass the string in the New instance call, like...
Code:
Public Class Form1
Private Sub OpenForm2Button_Click(sender As System.Object, e As System.EventArgs) Handles OpenForm2Button.Click
Dim gameOverView = New Form2(Me.VideoGame.Text)
gameOverView.Show()
End Sub
End Class
Code:
Public Class Form2
Private Property gameText As String
Public Sub New(game_text As String)
' This call is required by the designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
Me.gameText = game_text
End Sub
Private Sub Form2_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Me.Game.Text = Me.gameText
End Sub
End Class
unbelievable, I Love You Brah!
-
Sep 6th, 2014, 12:19 PM
#10
Re: Showing TextBox Text in a Label which is in another Form [Strange Issue]
I told you this in post 4
-
Sep 6th, 2014, 01:05 PM
#11
Thread Starter
Lively Member
Re: Showing TextBox Text in a Label which is in another Form [Strange Issue]
Originally Posted by ident
I told you this in post 4
Also thank you, i just didn't understand you
-
Sep 6th, 2014, 01:07 PM
#12
Re: Showing TextBox Text in a Label which is in another Form [Strange Issue]
Just for future reference the textbox should be private. You should not access it directly.
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
|