By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,992 Members | 1,339 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,992 IT Pros & Developers. It's quick & easy.

passing values to open form in vb.net

P: 64
Hi all

I am developing windows application using vb.net.I want to pass values to open form.I am opening only one form when user click the buttons several times.Useing delegate i am passing values for first time.Next time when user click the button i want to pass value to open form.How to pass value to open form.Can anyone help me plz.Thanx in advance

Code I used,

Form1 Code:

Public Delegate Sub GreetingDelegate(ByVal MsgString As String, ByVal MsgString1 As String)

Dim frm As Form

For Each frm In My.Application.OpenForms

'If frm Is My.Forms.Form2 Then
' MessageBox.Show("hii")
'End If
Dim x1 As String = frm.ToString()
Dim x2 As String = My.Forms.Form2.ToString()
If x1 = x2 Then
im = New Form2

MessageBox.Show("visible")
Exit Sub
End If
Next

im = New Form2(Textbox1.Text, Textbox2.Text)
im.Show()
Dim MyGreeting As GreetingDelegate
MyGreeting = New GreetingDelegate(AddressOf im.GoodMoring)
MyGreeting.Invoke(Textbox1.Text,Textbox2.text)


Form2 Code:
dim _strname1 as String
dim _strname2 as String
Public Sub GoodMoring(ByVal nam1e As String, ByVal name2 As String)
_strname1 = name1
_strname2 = name2
Dim wbReceive As New WebBrowser
Me.ctlTabPages.Add(New TabPages.TabPage(_strname1, wbReceive, "Created: " & DateTime.Now.ToLongTimeString()))
End Sub
Nov 28 '07 #1
Share this Question
Share on Google+
3 Replies


dip_developer
Expert 100+
P: 648
Hi all
I am developing windows application using vb.net.I want to pass values to open form.I am opening only one form when user click the buttons several times.Useing delegate i am passing values for first time.Next time when user click the button i want to pass value to open form.How to pass value to open form.Can anyone help me plz.Thanx in advance
I have not understood your problem.....but passing value to another form is easy.....

while opening form you have correctly pass the arguments as

Expand|Select|Wrap|Line Numbers
  1.  Dim str As String = "hello world" 
  2. frm2 = New Form2(str)
  3. frm2.ShowDialog()
  4.  
define a parameter in the New() method of called form

Expand|Select|Wrap|Line Numbers
  1. Dim mystr As String 
  2.  
  3. Public Sub New(ByVal a As String)
  4. MyBase.New()
  5. mystr = a.ToString
  6. 'This call is required by the Windows Form Designer.InitializeComponent()
  7. 'Add any initialization after the InitializeComponent() call
  8. End Sub
  9.  
now in a button click event you can test whether the correct information across the form is passed or not.

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub Button2_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  3. MsgBox(mystr) 
  4. End Sub
  5.  
Nov 28 '07 #2

P: 64
I want to pass values to open form,Example i have two forms form1 and form2
form1 have one button,form2 contains one tab control,From form1 button click i am opening form2,generally whenever clicking the button form2 will keeps on opening.I am opening only one form for clicking button several times.I used following code for that,and i passing values using delegate for first time button click.Next time when i click the button the values should pass to open form without opening new form.It should be added in tab control.I am not using parent child relation here.

Hope u understood my question.

Form1 Code:

Public Delegate Sub GreetingDelegate(ByVal MsgString As String, ByVal MsgString1 As String)

In Form1 Button_Click event:
Dim frm As Form

For Each frm In My.Application.OpenForms

'If frm Is My.Forms.Form2 Then
' MessageBox.Show("hii")
'End If
Dim x1 As String = frm.ToString()
Dim x2 As String = My.Forms.Form2.ToString()
If x1 = x2 Then

//////Code needed here...

MessageBox.Show("visible")
Exit Sub
End If
Next

im = New Form2(Textbox1.Text, Textbox2.Text)
im.Show()
Dim MyGreeting As GreetingDelegate
MyGreeting = New GreetingDelegate(AddressOf im.GoodMoring)
MyGreeting.Invoke(Textbox1.Text,Textbox2.text)


Form2 Code:
dim _strname1 as String
dim _strname2 as String
Public Sub GoodMoring(ByVal nam1e As String, ByVal name2 As String)
_strname1 = name1
_strname2 = name2
Dim wbReceive As New WebBrowser
Me.ctlTabPages.Add(New TabPages.TabPage(_strname1, wbReceive, "Created: " & DateTime.Now.ToLongTimeString()))
End Sub
Nov 28 '07 #3

P: 64
how to find out the open form....
Nov 28 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.