473,405 Members | 2,300 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,405 software developers and data experts.

How do I refer to Startup Form Controls from another form.

An application has a startup form (Form1). A second form (frm2),
created from within Form1. Each form has a textbox.
To access the text in TextBox1 in frm2 from Form1, you use:

frm2.TextBox1.Text = "XXXXXX"

How do I refer to the TextBox1 controls Text property in Form1 from
frm2?

Form1.TextBox1.Text doesn't work and generates a designtime error:
Reference to a non-shared member requires an object reference.

Nov 21 '05 #1
3 2408
"JAPSTER" <wh*******@hotmail.com> schrieb:
An application has a startup form (Form1). A second form (frm2),
created from within Form1. Each form has a textbox.
To access the text in TextBox1 in frm2 from Form1, you use:

frm2.TextBox1.Text = "XXXXXX"

How do I refer to the TextBox1 controls Text property in Form1 from
frm2?


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

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #2
Here's the way I do it....

In form2: Add a form-level variable and change the constructor for form2:
Private ff As Form
#Region " Windows Form Designer generated code "
Public Sub New(ByVal fx As Form)
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
ff = fx
'Add any initialization after the InitializeComponent() call
............... ETC.
Then in the Load method of form2 you can do something like this:
Dim f As Form1

f = CType(ff, Form1)

TextBox1.Text = f.TextBox1.Text

......................

The above can be further simplified of you KNOW that you will ONLY be
instatiating this form from form1:

Private ff As form1
#Region " Windows Form Designer generated code "
Public Sub New(ByVal fx as Form1)
.....
ff=fx
.... etc.

Then in Load:

Textbox1.text=ff.Textbox1.Text

HTH,

Larry Woods

"JAPSTER" <wh*******@hotmail.com> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com...
An application has a startup form (Form1). A second form (frm2),
created from within Form1. Each form has a textbox.
To access the text in TextBox1 in frm2 from Form1, you use:

frm2.TextBox1.Text = "XXXXXX"

How do I refer to the TextBox1 controls Text property in Form1 from
frm2?

Form1.TextBox1.Text doesn't work and generates a designtime error:
Reference to a non-shared member requires an object reference.

Nov 21 '05 #3
I found a way to do it.

Add a new friend module.

Friend Mudule Module1
Friend Frm1 as Form1
Friend Frm2 as Form2
End Module

In Form1_Load add:

Frm1 = Me
Frm2 = New Form2
Frm2.Show()

In Textbox1_TextChanged on Form1 add:

Frm2.Textbox1.Text = Textbox1.Text

In Textbox1_TextChanged on Form2 add:

Frm1.Textbox1.Text = Textbox1.Text

That, I found, was the easiest method to solve this problem.
Thank all for your input.

Nov 21 '05 #4

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

Similar topics

5
by: mark s | last post by:
How can I make a checkbox that says "Do not show this again at startup" on my reminder form? Thanks! -- name: Mark S. email: huskie_009@hotmail.com *** Sent via Developersdex...
3
by: Douglas Buchanan | last post by:
Buttons don't work if form is opened on startup A2k If 'frmMain' is set to open by default at startup none of the buttons work. If 'frmMain' is opened from the database window then all the...
3
by: Joshua Ammann | last post by:
Hi, (Using Access 2000) I have two tables, similar to Customers and Orders. (Not an exact parallel, but works for this example.) On a form showing customer data, there is a tab control. One...
7
by: cefrancke | last post by:
I cant seem to find a straight answer on the following. I want to programmatically hide all menus except a basic custom report menu (during report preview) and right click pop-up A-Z sorting on...
2
by: Simon Harvey | last post by:
Hi all, I was wondering how most developers handle the initial startup of their Windows Forms applications? When you make an application in Visual Studio, the IDE places Main in the form that...
4
by: Tony Vitonis | last post by:
Hello. I've written an app that I want to "live" in the system tray. I want it to start up with just a tray icon showing, and if the user selects "Settings..." from the icon's context menu, to...
1
by: Robert | last post by:
I borrowed one of the forms from the MS Access Solutions database and altered it to fit my needs. The form was the 'EditProducts' form where you select a category from a combo which then populates...
9
by: jeff | last post by:
Hi All. I realize that when my Deployed winforms application starts, Windows needs to load the .net 2 framework before control is given to my application.... Is there anyway to either ... -...
16
by: Mike | last post by:
Hi, I have a form with some controls, and a different class that needs to modify some control properties at run time. Hoy can I reference the from so I have access to its controls and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.