473,769 Members | 2,246 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Simple forms question

JSM
Hi,

I have a form (FormA) which was loaded using Application.Run when my app
loads. This form has a button which loads Form B using "FormB myForm=new
FormB()". My question is, how do I access and modify the value of a control
on FormA from FormB?

I thought this would be easy but I was wrong.

Cheers,

John
Nov 15 '05 #1
4 1824
Expose a public property of type Form, from B. Assign A
to the public property. Then B has a reference to A, you
can iterate the controls collection to identify your
target control and manipulate it as you wish.
I'm sure there's a more elegant solution, but this will
work in the interim.

-----Original Message-----
Hi,

I have a form (FormA) which was loaded using Application.Run when my apploads. This form has a button which loads Form B using "FormB myForm=newFormB()". My question is, how do I access and modify the value of a controlon FormA from FormB?

I thought this would be easy but I was wrong.

Cheers,

John
.

Nov 15 '05 #2
JSM
Hi Mikael,

The example you gave sends information from A to B. What I can't figure out
is how can I send information from B to A. Since A was created using
Application.Run I don't have an instance name of A which I could use.

Cheers,

John

"Mikael" <_N******@chell o.se> wrote in message
news:O0******** *****@tk2msftng p13.phx.gbl...
Heres a simple example using a property.

Regards, Mikael

using System;
using System.Windows. Forms;

public class A : Form
{
private Button btn = new Button();
B b = new B();

public A()
{
btn.Text = "Load form B";
btn.Click += new EventHandler(bt n_Click);
this.Controls.A dd(btn);
}

private void btn_Click(objec t sender, EventArgs e)
{
b.Show();
}

protected override void OnMouseDown(Mou seEventArgs e)
{
b.LabelText = "Hello from A!";
}
static void Main()
{
Application.Run (new A());
}
}

public class B : Form
{
private Label lbl = new Label();
public B()
{
lbl.Dock = DockStyle.Fill;
this.Controls.A dd(lbl);
}

public string LabelText
{
set { lbl.Text = value; }
}
}

"JSM" <12*@123.com> skrev i meddelandet
news:uA******** ******@TK2MSFTN GP12.phx.gbl...
Hi,

I have a form (FormA) which was loaded using Application.Run when my app
loads. This form has a button which loads Form B using "FormB myForm=new
FormB()". My question is, how do I access and modify the value of a

control
on FormA from FormB?

I thought this would be easy but I was wrong.

Cheers,

John


Nov 15 '05 #3
{
A a=new A();
Application.Run (a);
}

Does this help?

"JSM" <12*@123.com> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
Hi Mikael,

The example you gave sends information from A to B. What I can't figure out is how can I send information from B to A. Since A was created using
Application.Run I don't have an instance name of A which I could use.

Cheers,

John

"Mikael" <_N******@chell o.se> wrote in message
news:O0******** *****@tk2msftng p13.phx.gbl...
Heres a simple example using a property.

Regards, Mikael

using System;
using System.Windows. Forms;

public class A : Form
{
private Button btn = new Button();
B b = new B();

public A()
{
btn.Text = "Load form B";
btn.Click += new EventHandler(bt n_Click);
this.Controls.A dd(btn);
}

private void btn_Click(objec t sender, EventArgs e)
{
b.Show();
}

protected override void OnMouseDown(Mou seEventArgs e)
{
b.LabelText = "Hello from A!";
}
static void Main()
{
Application.Run (new A());
}
}

public class B : Form
{
private Label lbl = new Label();
public B()
{
lbl.Dock = DockStyle.Fill;
this.Controls.A dd(lbl);
}

public string LabelText
{
set { lbl.Text = value; }
}
}

"JSM" <12*@123.com> skrev i meddelandet
news:uA******** ******@TK2MSFTN GP12.phx.gbl...
Hi,

I have a form (FormA) which was loaded using Application.Run when my app loads. This form has a button which loads Form B using "FormB myForm=new FormB()". My question is, how do I access and modify the value of a

control
on FormA from FormB?

I thought this would be easy but I was wrong.

Cheers,

John



Nov 15 '05 #4
if in FormB's constructor you have a param which receieves a referance of a
form control.

then when you call FormB from FormA use the this keyword to pass the
referance.

FormB will then be able to access public elements in FormA.
"JSM" <12*@123.com> wrote in message
news:uA******** ******@TK2MSFTN GP12.phx.gbl...
Hi,

I have a form (FormA) which was loaded using Application.Run when my app
loads. This form has a button which loads Form B using "FormB myForm=new
FormB()". My question is, how do I access and modify the value of a control on FormA from FormB?

I thought this would be easy but I was wrong.

Cheers,

John

Nov 15 '05 #5

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

Similar topics

3
267
by: kirk g | last post by:
When I run the following code: OleDbConnection conn = new OleDbConnection( @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\moneymakin.mdb"); String stmt = "INSERT INTO Person (FirstName, LastName, Email, LoginID, Password) VALUES (" + "'" + this.m_perFirstName + "', '" + this.m_perLastName +
13
2366
by: LRW | last post by:
Having a problem getting a onSubmit function to work, to where it popsup a confirmation depending on which radiobutton is selected. Here's what I have: function checkdel() { if (document.getElementById"].value=='1') { confirm('Are you sure you want to delete this file?'); } } ......
6
1919
by: someguy | last post by:
Hi, I'm trying to accomplish the following on a form on which i have removed navigational buttons (I apologize in advance if this is too many questions); The two easy ones are.... 1) When the user opens the forms I would like it to open to a blank form so they can create a new record (I don't want fields populated with the first record from the table). The user should also have the option of
0
7566
by: Tal Sharfi | last post by:
Hi everyone I recently had the need for StringGrid object same as the one that Delphi has. An object that helps show lists of other objects in a simple grid. I searched the news groups and found none, so, I wrote one and decided to share it with you. It's a very simple one with few functions. I derived a DataGrid and added to it a DataTable to hold the data. The object itself is handling the synchronization between them, because...
2
8403
by: Hazzard | last post by:
I just realized that the code I inherited is using all asp.net server controls (ie. webform controls) and when I try to update textboxes on the client side, I lose the new value of the textbox when submitting the form to update the database. The server doesn't have the client side value any more. It seems to me that as I begin to write the client side javacript code for form validation and client side editing capabilities in order to save...
1
1017
by: damiensawyer | last post by:
Hi all, I hope that this question isn't too simple... I am storing all of my webforms in a /forms directory (with the exception of Default.aspx). I have created the following code in Global.asax which is supposed to forward people to the login page if they make a request (for any page) without an active session. Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
2
1176
by: Allain Bøge | last post by:
It is really a simple question. Visual Basic .NET (2003) I create 2 forms (Form1 and Form2) I create a checkbox in Form1 (checkbox1) I create a checkbox in Form2 (checkbox1) I go to Form1 doubleclick on checkbox1 and alters the code
2
1875
by: iwdu15 | last post by:
hey, i was wondering if 1) anyone could tell me whats wrong with my code, i did a little fixing to the msdn version fo this, or 2) how to make a simple program that will connect and listen for connections async. if the user pushes the selected buttons. i just want a program that connects to another computer on the port and IP address selected and if the other computer is listening, then connect to it but this code doesnt work : Imports...
5
1702
by: Byron | last post by:
I need to create an application that uses primarily a single form rather than an SDI that creates a new form for everythting. However, I don't want an MDI style application since the users I'm dealing with would be overwhelmed with it. The approach I tried in the past was to use MDI, but made all the child windows occupy the entire parent area without a frame so it looked like a single window. I also allowed only a single instance of...
6
2037
by: Jim M | last post by:
I've been distributing a fairly mature, very specific MS Access application to end users in small offices of colleges for several years now. This is a part-time venture and low volume operation- this is somewhat of a hobby for me. Many of my end users are computer phobic and get little support from their IT departments. It is a split database so the datafile gets put on the file server and the 3 different front ends get put on each local...
0
9422
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10035
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
9984
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
9851
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
8863
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7403
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5293
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...
2
3556
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2811
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.