Hi Winder,
There are lot of ways to accomplish ur objective:
1. As xtramac suggested u can use public variables.
2. U can also use global variables, which gets initialised from form1, and u can read those from form2.
3. You can do it through constructor itself.
Lemme give u a small code snippet[C#] to support point 3.
In Form1[anywhere u want to call form2]
form2 myForm2=new form2(string Username);
myForm2.Show();
-------------------------------------------------------
In Form2 [Consructor]
public form2(string DataFromForm1)
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
So, DataFromForm1 will contain the value u passed from form1.
Hope it helped else revert back, incase u need more clarification.
____________________________
Bite the bit
sanc1@rediffmail.com
Hi Winder,
My previous code snippet was in C#. Here is the equivalent VB.Net code...
Form1
------------------
Public Class Form1
Inherits System.Windows.Forms.Form
Public msgToPass As String
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
msgToPass = "It's fun"
Dim myForm2 As New Form2(msgToPass)
myForm2.Show()
End Sub
End Class
Form2
------------------
Public Class Form2
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public msgReceived As String
Public Sub New(ByVal msgReceived)
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call MessageBox.Show(msgReceived)
End Sub
#End Region
End Class
Look, in Form1 and Form2 code, whatever changes I made, is in bold. Hope it's clear to you now, and this is what you are looking for. If not so, hit back again
____________________________
Bite the bit
sanc1@rediffmail.com
sanc1, can you help me on this ? it seems that my buffer size is too small, and i have only receive part of the XML data which i am getting from, so when i returndata, i only get part of it.
Can you help ? Anyone ?
Public num As Integer = 0
Public ns As NetworkStream
Public returndata As String
Public client As New TcpClient
Public Function receive()
ns = client.GetStream()
Dim bytes(client.ReceiveBufferSize.MaxValue) As Byte
ns.Read(bytes, 0, CInt(client.ReceiveBufferSize))
returndata = System.Text.Encoding.ASCII.GetString(bytes, 0, bytes.Length)
Return returndata
End Function