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 4 1801
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
.
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******@chello.se> wrote in message
news:O0*************@tk2msftngp13.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(btn_Click); this.Controls.Add(btn); }
private void btn_Click(object sender, EventArgs e) { b.Show(); }
protected override void OnMouseDown(MouseEventArgs 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.Add(lbl); }
public string LabelText { set { lbl.Text = value; } } }
"JSM" <12*@123.com> skrev i meddelandet news:uA**************@TK2MSFTNGP12.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
{
A a=new A();
Application.Run(a);
}
Does this help?
"JSM" <12*@123.com> wrote in message
news:%2****************@TK2MSFTNGP10.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******@chello.se> wrote in message news:O0*************@tk2msftngp13.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(btn_Click); this.Controls.Add(btn); }
private void btn_Click(object sender, EventArgs e) { b.Show(); }
protected override void OnMouseDown(MouseEventArgs 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.Add(lbl); }
public string LabelText { set { lbl.Text = value; } } }
"JSM" <12*@123.com> skrev i meddelandet news:uA**************@TK2MSFTNGP12.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
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**************@TK2MSFTNGP12.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
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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,...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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-...
|
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...
|
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...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
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...
|
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...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
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....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
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...
| |