473,320 Members | 2,146 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Form interaction

Hi all, I have a simple question. I have 2 form; form1 is the main form and
form2 is a secondary form. Just wondering if is possible to change the text
value of a control label placed in the form1 from form2. Example, I have put
a button inside the form2 like this:
________________
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim xform1 As Form1

xform1.Label1.Text = "test"

End Sub

___________________

This code produce an error :(

Thanks.
Nov 21 '05 #1
4 1129
The code above should produce a NullReference exception as there is
nothing ;) attached to the xForm1 variable.
You will need a reference to the main form in the 'child' form to
interact with it.

eg. (much abbreviated)
class Form1

' Create the child form with a reference to parent and display
Private Sub LaunchForm2( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs _
) Handles Launch.Click

dim frm as new Form2(me)
frm.Show()

end sub

end class
class Form2

' store the reference to the parent
public sub new ( _
parent as Form _
)
_parent = parent

<rest of code>

end sub
' Update the parent through the reference
Private Sub UdpateForm1( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs _
) Handles ChangeText.Click

_parent.Label1.Text = "Hello World"

end sub

end class

hth,
Alan.

Nov 21 '05 #2
Poldoj,

Assuming that I understand you, than add in your main form by the instancing
of your form2
\\\
frm2.owner = me
///
Than it is in form2
\\\
Owner.Label1.Text = "test"
///
I hope this helps,

Cor
Nov 21 '05 #3

Using the owner property is faster/easier than creating your own
association between the forms; the only caveat I would make is to be
sure that Form1 'owns' Form2

i.e.
if you minimize Form1, Form2 should be minimized as well
if you close Form1, Form2 should close as well
hth,
Alan.

Nov 21 '05 #4
Thanks both sincerely, I add the reference and then all worked.
^_^
Nov 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
by: Pete | last post by:
I have form/select which executes a function using onchange. No problem. However, when I validate the page with a strict HTML 4.01 doctype at http://validator.w3.org, it demands either an action or...
0
by: David Virgil Hobbs | last post by:
What programming codes will enable me to achieve interaction between vb or c# and HTML form values, without a page reload occurring every time a script is run? At least with javascript and vb...
4
by: Stuart Perryman | last post by:
Hi, I have the following code which works just fine in IE6 but not in Firefox. It is an extract of several table rows each with an individual form. It is generated by php. <form...
0
by: David Virgil Hobbs | last post by:
While studying the asp.net javascript problem I saw and used pages about asp.net basics at http://www.sitepoint.com/article/815/4 and...
2
by: thomasp | last post by:
Using VB 2005 Beta. I have a form containing a DataGirdView. The cell enter, cell validating, row enter, row validating events have a good bit of code that gets excuted for each of these...
3
by: Vitaly Zayko | last post by:
Is it possible to attach a form (C# .NET 2) to windows service and show it in OnStart event? When I tried to do this in general (new, Show()) way it just didn't do anything nor gave me any errors....
5
by: Mike Dee | last post by:
Is it possible to dynamically create a new form object (form1), then create a new form field object and add it form1, and then add form1 to the current document? I need to do all this in script...
19
by: AMP | last post by:
I have a simple question. If i have a button on form1 that creates : Form2 newform = new Form2(); newform.Show(); As I click the button a new form shows,but acording to my code each one has...
3
by: wavedave | last post by:
Hello everyone - I'm trying to build a .NET application (C#) in which my program acts as an add-on to another existing application, providing some additional functionality. The way I want the UI...
0
by: Omar Abid | last post by:
Reason of this project: The Microsoft.VisualBasic.Interaction class exposes many useful commands and methods that were available in Visual Basic like AppActivate, Beep, Callbyname... This...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.