473,498 Members | 1,679 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C# Question

gwi5727
4 New Member
what is the code to display text in a label in form B coming from a textbox in form A. See attached diagram
Attached Images
File Type: jpg untitled.JPG (16.7 KB, 92 views)
Mar 22 '07 #1
8 1135
channaJ
67 New Member
what is the code to display text in a label in form B coming from a textbox in form A. See attached diagram
Are you calling FormB from FormA..?

Anyway...you have to create a public property in FormA, which returns the Text in the text box. Then you can access this property from FormB.

Does it make sence..? Let me know if not.
Mar 23 '07 #2
gwi5727
4 New Member
It doesn't make sense.
Apr 12 '07 #3
gwi5727
4 New Member
I'm not calling form A from form B. All I want is to display the input in the textbox in form A in the label in form B.
In other words, whatever is input in the textbox area in form A, I want it to appear in the label in form B. These are two different forms.
Apr 12 '07 #4
Plater
7,872 Recognized Expert Expert
Something has to be the parent here.
If FormA doesn't call FormB and FormB doesn't call FormA.
Then who called them? (who created/Show() them?)
It's a tricky situation though.
You will need public methods on both forms probably. Having at least GET{} for the textbox and SET{} for the label.
Whoever the Parent is, will need a function that can be accessed from the form with the textbox, so that when the text in the textbox is changed, it calls that function, sending it the contents of the textbox.text property and the function can then SET the text of the label property using the public method you created on that form.

Using seperate forms is always a pain in the butt.
Apr 12 '07 #5
gwi5727
4 New Member
Can u express your answer in code form?
Apr 12 '07 #6
Plater
7,872 Recognized Expert Expert
I can give it a try...this won't be the best way to solve this problem, but I am pretty sure it will work.

In the Form that has the LABEL you wish to set, create a public function:
Expand|Select|Wrap|Line Numbers
  1. public void myTextBox_KeyPress(object sender, KeyPressEventArgs e)
  2. {
  3.        MyLabel.Text=((TextBox)sender).text;
  4. }
  5.  
In the form that has the TEXTBOX you wish to read from, add a custom keypress even handler to the textbox (will be in the designer code)
Expand|Select|Wrap|Line Numbers
  1. this.myTextBox.KeyPress += new System.Windows.Forms.KeyPressEventHandler(FORMA.myTextBox_KeyPress);
  2.  
changing the names of FORMA, myTextBox and myLabel to the names of your objects

Should be all you need...
Apr 12 '07 #7
nmsreddi
366 Contributor
Hello

If you dont want to go for any your own properties then you can simply solve this by creating a public variable in formB ,then when you are moving from A to form B ,at that time ,how ever you have to create an object of formB using that object you can access the public variable of formB there it self you can assign the value of textbox to that variable in formB

Samplecode
//create a public variable in formB ;

string val;

//formA
{

fromB b=new formB();
b.val=textboxa.text;
b.show();

now you can use the vale of val in formB directly

labelB.text=val;

try it out it work fine
Apr 14 '07 #8
int08h
28 New Member
If as I understand, you call the Form with TextBox and Button from the Form with Label, and want to update the Text of label in reference with the TextBox by clicking the Button

A delegate may work with this problem

first define a delegate in namespace:
public delegate void TextUpdate(string str);

than in Form A define a member as TextUpdate:
private TextUpdate update;

modify the cunstructor of Form A as below:
private FormA()
{
InitializeComponent();
}// Hide default constructor

public Form2(TextUpdate arg)
: this()
{
update = arg;
}

finally for Form A, raise the Click event of Button as below:
private void buttonName_Click(object sender, EventArgs e)
{
update(this.textBoxName.Text);
}

In Form B, use delegate to instantiate Form a:
Form2 f = new Form2(
delegate(string str)
{
this.labelName.Text = str;
}
);//use annon method

It works fine here
not good English, sorry~
Apr 14 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

1
3081
by: Mohammed Mazid | last post by:
Can anyone please help me on how to move to the next and previous question? Here is a snippet of my code: Private Sub cmdNext_Click() End Sub Private Sub cmdPrevious_Click() showrecord
3
4993
by: Stevey | last post by:
I have the following XML file... <?xml version="1.0"?> <animals> <animal> <name>Tiger</name> <questions> <question index="0">true</question> <question index="1">true</question> </questions>
7
2624
by: nospam | last post by:
Ok, 3rd or is it the 4th time I have asked this question on Partial Types, so, since it seems to me that Partial Types is still in the design or development stages at Microsoft, I am going to ask...
3
3054
by: Ekqvist Marko | last post by:
Hi, I have one Access database table including questions and answers. Now I need to give answer id automatically to questionID column. But I don't know how it is best (fastest) to do? table...
10
3386
by: glenn | last post by:
I am use to programming in php and the way session and post vars are past from fields on one page through to the post page automatically where I can get to their values easily to write to a...
10
3678
by: Rider | last post by:
Hi, simple(?) question about asp.net configuration.. I've installed ASP.NET 2.0 QuickStart Sample successfully. But, When I'm first start application the follow message shown. ========= Server...
53
4012
by: Jeff | last post by:
In the function below, can size ever be 0 (zero)? char *clc_strdup(const char * CLC_RESTRICT s) { size_t size; char *p; clc_assert_not_null(clc_strdup, s); size = strlen(s) + 1;
56
4688
by: spibou | last post by:
In the statement "a *= expression" is expression assumed to be parenthesized ? For example if I write "a *= b+c" is this the same as "a = a * (b+c)" or "a = a * b+c" ?
2
4249
by: Allan Ebdrup | last post by:
Hi, I'm trying to render a Matrix question in my ASP.Net 2.0 page, A matrix question is a question where you have several options that can all be rated according to several possible ratings (from...
3
2536
by: Zhang Weiwu | last post by:
Hello! I wrote this: ..required-question p:after { content: "*"; } Corresponding HTML: <div class="required-question"><p>Question Text</p><input /></div> <div...
0
7200
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...
1
6884
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
5460
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,...
1
4904
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...
0
3090
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...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1416
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 ...
1
651
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
287
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...

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.