473,657 Members | 2,758 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Accessing controls on another form.

Hi

I posted this to the .Net general newsgroup and got a reply from "Morten"
who has given me an answer but in C# a language I have never worked with.
VB.Net is still very new to me, I was hoping someone here in the VB.net
group could help me a little. I have copied the posts to here.

Morten has given me a code snippet in C# but where do I use it and what is
the VB.Net equivalent.

Thanks DaveG

''''''''' Orig Post ''''''''''''''
Hi

Using VB.net 2003

I know how to access controls on a 2nd form after declaring the form
in the first.

But how do I access the controls on the original form from the 2nd
form.

(in frmMain)
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e
As System.EventArg s) Handles Button1.Click
Dim form2 As New Form2
form2.TextBox1. Text = TextBox1.Text
form2.Show()
End Sub

(in Form2)
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e
As System.EventArg s) Handles Button1.Click
Dim form1 As New Form1
form1.TextBox1. Text = TextBox1.Text
form1.Update()
Me.Close()

End Sub
Form2 textbox updates ok
The textbox in form1 does not update and still holds the original text
before opening Form2

This is just a simple example I cannot get working, once I can get
this working the I should not have problems with the actual code I
need to use.

There must be a simple answer to this....???

Thanks in advance for any help given

DaveG
Hi Dave,

You need to pass a reference to your 1st form when declaring the 2nd,
typically

Form2 f2 = new Form2(this); // Me in VB

Overload the constructor of the 2nd form to accept a 1st form
parameter. Store the parameter for later use

On Sat, 30 Apr 2005 13:29:05 +0200, DaveG <no**********@d aveg.co.uk>
wrote:

Thanks Morten

Now the problem is I have used the overload in normal funtions and subs
but never with the constructors, so now I'm a little lost, I understand
the reasons for the overload..... so the New form2(Me) will be excepted
bur how to implement it is where I am stuck......

Dave, overloading a constructor is done the exact same way, although I'm
not sure how the VB syntax is. Store the Form1 reference for later use.

private Form1 myParent;

public Form2(Form1 f)
{
myParent = f;
}

then simply call

myParent.Method OrSimilarInForm 1()

whenever you need.

Nov 21 '05 #1
3 3240
Dave,

There are many roads that goes to Rome

Your mainform
\\\
Dim frm As New Form2
frm.Owner = Me
frm.Show()
///
You form where you want to use it.
\\\
MessageBox.Show (DirectCast(Me. Owner, Form1).TextBox1 .Text)
///
Assuming that you have a textbox1 on form1

I hope this helps,

Cor
Nov 21 '05 #2
"DaveG" <no**********@d aveg.co.uk> schrieb:
I posted this to the .Net general newsgroup and got a reply from "Morten"
who has given me an answer but in C# a language I have never worked with.
VB.Net is still very new to me, I was hoping someone here in the VB.net
group could help me a little. I have copied the posts to here.


Depending on the situation direct access to the parent form isn't required
in order to update the parent form upon closing the other form:

<URL:http://groups.google.d e/groups?selm=%23 7sTDoqHFHA.3208 %40TK2MSFTNGP10 .phx.gbl>

In MDI environments:

\\\
DirectCast(Me.M diParent, MainForm).TextB ox1.Text = ...
///

Providing a reference to an application's main form
<URL:http://dotnet.mvps.org/dotnet/faqs/?id=accessmainf orm&lang=en>

In VB 2005 you can access form instances more easily with 'My.Forms.*'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #3
Thanks guys for your quick responses.

I think I am crawling along one of these roads to Rome. now I can see how
I am supposed to implement a basic setup I'm sure I can play a little, if
not "I shall be back".

DaveG

On Sun, 01 May 2005 09:54:54 +0200, DaveG wrote:
Hi

I posted this to the .Net general newsgroup and got a reply from
"Morten" who has given me an answer but in C# a language I have never
worked with. VB.Net is still very new to me, I was hoping someone here
in the VB.net group could help me a little. I have copied the posts to
here.

Morten has given me a code snippet in C# but where do I use it and what
is the VB.Net equivalent.

Thanks DaveG

''''''''' Orig Post ''''''''''''''
Hi

Using VB.net 2003

I know how to access controls on a 2nd form after declaring the form
in the first.

But how do I access the controls on the original form from the 2nd
form.

(in frmMain)
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e
As System.EventArg s) Handles Button1.Click
Dim form2 As New Form2
form2.TextBox1. Text = TextBox1.Text
form2.Show()
End Sub

(in Form2)
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e
As System.EventArg s) Handles Button1.Click
Dim form1 As New Form1
form1.TextBox1. Text = TextBox1.Text
form1.Update()
Me.Close()

End Sub
Form2 textbox updates ok
The textbox in form1 does not update and still holds the original
text before opening Form2

This is just a simple example I cannot get working, once I can get
this working the I should not have problems with the actual code I
need to use.

There must be a simple answer to this....???

Thanks in advance for any help given

DaveG Hi Dave,

You need to pass a reference to your 1st form when declaring the 2nd,
typically

Form2 f2 = new Form2(this); // Me in VB

Overload the constructor of the 2nd form to accept a 1st form
parameter. Store the parameter for later use

On Sat, 30 Apr 2005 13:29:05 +0200, DaveG <no**********@d aveg.co.uk>
wrote:

Thanks Morten

Now the problem is I have used the overload in normal funtions and subs
but never with the constructors, so now I'm a little lost, I understand
the reasons for the overload..... so the New form2(Me) will be excepted
bur how to implement it is where I am stuck......

Dave, overloading a constructor is done the exact same way, although I'm
not sure how the VB syntax is. Store the Form1 reference for later use.

private Form1 myParent;

public Form2(Form1 f)
{
myParent = f;
}

then simply call

myParent.Method OrSimilarInForm 1()

whenever you need.

Nov 21 '05 #4

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

Similar topics

3
15099
by: Tom Meuzelaar | last post by:
Hello: I'm using VB6 in VS enterprise. I'd like to place an HTML form inside a VB container, have a user fill out the form information, click a submit button, and then have the program capture the field values and write them to an ASCII file on the hard drive. Can anyone confirm that this is even possible? I have dredged up one article "Accessing the Internet Explorer Document Object Model from Visual Basic 5.0" (Asmi, 1998) that covers...
4
12097
by: Jim Heavey | last post by:
Hello, I have created a form which I intend to use a a dialog box. It has a few controls on that form and I changed the properties of those controls to "public" with the idea that I could access those controls from the "calling form", but I am unable to access/see those controls. Why? Here are portions of my code Here I am substantiating the new form and trying to set values for the controls on that form...
4
4339
by: Andrew Diabo | last post by:
I have 2 forms (Form1 and Form2) in my C# project. I created the second form from the main form like so: Fom2 aForm = new Form2(); aForm.ShowDialog(); How do I access the properties of a control (label1) in Form1 from Form2? Thanks Andrew
3
1336
by: Tim Fitzgerald | last post by:
Hello all, I have no problem accessing another form in my app.. however, when I try to access a ListView on a different form, I come up empty... Basically, Dim pForm As New frmMain Dim iCount As Integer iCount = pForm.lvJobList.Items.Count
0
1419
by: Geraldine Hobley | last post by:
Hello I have a problem whereby I have a treeview control on one form called projecttree and I wish to clea the nodes from this control in another form The form that contains the treeview is called projecttree and the form that I wish to clear the node from the tree, (because I'm connecting to a different database) is called frmConnections The forms are on the screen at the same time, and they are of type crownwood docking control ...
5
1942
by: RSH | last post by:
I havent been able to set a property from another class with out getting some sort of error. Can someone please tell me what I'm doing wrong here? Public Class Form1
4
3622
by: raj_genius | last post by:
I hav two queries, whc are as follows: FIRSTLY: is it possible to access the controls(by name) of a parent form(MDI) from its child forms??if yes then how??plzz provide a coded example in VB if possible.. for example..i hav a menu in the parent form named "Administrator" whic has an item "mnuLogIn"..now when i click on login..another child form named "frmLogIn" is displayed..what i want to happen is this: when login form(frmLogIn) is...
8
2176
by: colmkav | last post by:
Hi, could someone tell me how I can check whether a database is open by name eg something like db("mydbname")
3
2209
by: M K | last post by:
I have 2 classes. One where the form resides and I created another one for all the database stuff. after i get data from the db i want to be able to update the form. I have the namespace of where the form code is but how do i get to the controls themselves. newbie in the class world.. still trying to figure it all out :) Thanks for any help...
2
3042
by: San24 | last post by:
Guys, Let me explain the application I have - Form > Main Tab Control > Main Tab Page > User Control > Sub Tab Control > Sub Tab Page > User Control > Contols/Text Box. Form - The main form Main Tab Control - This contains Main Tab Pages.
0
8385
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8821
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8723
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8502
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8602
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4150
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1941
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.