Question about Setting Properties.

D

David

Is this code correct? My Question is On Form1 where I set
using value as string Do I address Value on form2 to set
this? or do I just set by Frm1.txtbox1value() = "Form2
just sent this back". So Value = "Form2 just sent this
back" right? Thanks for any help.


Public Class Form1
Inherits System.Windows.Forms.Form

Private Sub Button1_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
Button1.Click
Dim frm2 As WindowsApplication8.Form2
frm2 = New WindowsApplication8.Form2
frm2.Show()
End Sub
Public Property txtbox1value() As String
Get
Return Me.TextBox1.Text
End Get
Set(ByVal Value As String)
Me.TextBox1.Text = Value
End Set
End Property
End Class

Public Class Form2
Inherits System.Windows.Forms.Form

Private Sub TextBox1_TextChanged(ByVal sender As
Object, ByVal e As System.EventArgs) Handles
TextBox1.TextChanged
Dim frm1 As WindowsApplication8.Form1
frm1 = New WindowsApplication8.Form1
frm1.txtbox1value() = "Form2 just sent this back"
End Sub

Private Sub Button1_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
Button1.Click
Me.Close()
End Sub

Private Sub Form2_Load(ByVal sender As Object, ByVal
e As System.EventArgs) Handles MyBase.Load
Dim frm1 As WindowsApplication8.Form1
frm1 = New WindowsApplication8.Form1
Me.TextBox1.Text = frm1.txtbox1value
End Sub
End Class
 
T

Tom Leylan

David said:
Is this code correct? My Question is On Form1 where I set
using value as string Do I address Value on form2 to set
this? or do I just set by Frm1.txtbox1value() = "Form2
just sent this back". So Value = "Form2 just sent this
back" right? Thanks for any help.

Nope :) Your code indicates some confusion in how things work. I'll
suggest that you should get a solid sense of what declaring variables does,
where they are created, variable scope and such. Then what creating an
object (in your example a form but an object nonetheless) does.

I realize that you're asking for help but it's a "concept" thing not a "oh
just change these few lines of code" type of thing. I think you're going to
have to read documentation in the form of tutorials or a book. It would
save you hours of experimentation in the long run.

Tom
 
C

Cor

Hi David,

For me with this questions is always, is form2 a dialogform (A startup or
something else to get some information you do not want all the time on your
mainform)

Than your code can be a lot simpler. Although this is a crazy function, it
changes a textbox on form1 using another form. but I keep your sample.

(It is a lot of code to change in a mail message so watch typos)

I hope this helps,

Cor

Public Class Form1
Inherits System.Windows.Forms.Form

Private Sub Button1_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
Button1.Click
Dim frm2 as New Form2
frm2.txtbox1value = me.textbox1.text
frm2.Showdialog()
dim myreturnvalue = frm2.txtbox1value
frm2.dispose
Public Class Form2
Inherits System.Windows.Forms.Form
private myvalue as string
Public Property txtbox1value() As String
Get
Return myvalue
End Get
Set(ByVal Value As String)
myvalue = Value
End Set
End Property
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top