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

displaying text from a different class into Form1.textBox1

I'm having trouble getting items from different classes to display in
my textBox.

e.g.

private void button2_Click(object sender, System.EventArgs e)
{
someData sd = new someData();
sd.showData();
}

class someData : Form1
{
public void showData()
{
textBox1.Text="Some Stuff Here";
}
}

nothing shows up in the textBox when I press the button

I also tried

class someData : SomeOtherClassHere
{
public void showData()
{
Form1 f = new Form1();
f.textBox1.Text="Some Complete BS Here";
}
}

which is what I'd like to do, use a form that uses a class other than
Form1

I'm a pretty new programmer and don't have much experience with
windows forms, any help is much appreciated. Thanks
Nov 15 '05 #1
3 5525
polarz,

I'm not sure I understand your problem completely. I'm going to do the best
I can...

.... are you looking for something like the following?

#region Example code
public class SomeData : SomeOtherClassHere {
public void ShowData(Form1 form) {
Form1.textBox1.Text = "Some Stuff Here";
}
}

public class Form1 {
....
private void button2_Click(object sender, System.EventArgs e) {
SomeData sd = new SomeData();
Form1 theForm = (Form1) sender;
sd.ShowData(theForm);
}
#endregion

That will create a class named SomeData whose instances have a method that
can effect an instance of the Form1 class in such a way as to modify the
Text property of their textBox1 field.

Is that what you wanted? If not, please clarify.

Thank you,
Max Guernsey
http://www.harbingersoftware.com

"polarz" <po****@hotmail.com> wrote in message
news:qa********************************@4ax.com...
I'm having trouble getting items from different classes to display in
my textBox.

e.g.

private void button2_Click(object sender, System.EventArgs e)
{
someData sd = new someData();
sd.showData();
}

class someData : Form1
{
public void showData()
{
textBox1.Text="Some Stuff Here";
}
}

nothing shows up in the textBox when I press the button

I also tried

class someData : SomeOtherClassHere
{
public void showData()
{
Form1 f = new Form1();
f.textBox1.Text="Some Complete BS Here";
}
}

which is what I'd like to do, use a form that uses a class other than
Form1

I'm a pretty new programmer and don't have much experience with
windows forms, any help is much appreciated. Thanks

Nov 15 '05 #2
Hello Max, thanks for the reply. When I try to use your code I get an
unspecified cast error. I see the logic of your code but I can't get
it to work. I have the class in a different file named Class2.cs, but
it's in the same namespace. Here is how I have my code.

class someData : System.ApplicationException //this is in Class2.cs
{
public void ShowMyData(NewsMyWay.Form1 form)
{
form.textBox1.Text = "Some Stuff Here";
}
}

private void button2_Click(object sender, System.EventArgs e)
{
someData sd = new someData();
Form1 theForm = (Form1) sender;
sd.ShowMyData(theForm);

}

Basicly I'm trying to alter a textBox and a DataGrid from another
class and am having trouble with both. I'm sure this is a simple
solution but I can't see it :/

On Fri, 30 Jan 2004 03:53:01 -0800, "Max Guernsey"
<ma**********@harbingersoftware.com> wrote:

I'm not sure I understand your problem completely. I'm going to do
the best
I can...

.... are you looking for something like the following?

#region Example code
public class SomeData : SomeOtherClassHere {
public void ShowData(Form1 form) {
Form1.textBox1.Text = "Some Stuff Here";
}
}

public class Form1 {
....
private void button2_Click(object sender, System.EventArgs e) {
SomeData sd = new SomeData();
Form1 theForm = (Form1) sender;
sd.ShowData(theForm);
}
#endregion

That will create a class named SomeData whose instances have a method
that
can effect an instance of the Form1 class in such a way as to modify
the
Text property of their textBox1 field.

Is that what you wanted? If not, please clarify.

Thank you,
Max Guernsey
http://www.harbingersoftware.com

"polarz" <po****@hotmail.com> wrote in message
news:qa********************************@4ax.com...
I'm having trouble getting items from different classes to display in
my textBox.

e.g.

private void button2_Click(object sender, System.EventArgs e)
{
someData sd = new someData();
sd.showData();
}

class someData : Form1
{
public void showData()
{
textBox1.Text="Some Stuff Here";
}
}

nothing shows up in the textBox when I press the button

I also tried

class someData : SomeOtherClassHere
{
public void showData()
{
Form1 f = new Form1();
f.textBox1.Text="Some Complete BS Here";
}
}

which is what I'd like to do, use a form that uses a class other than
Form1

I'm a pretty new programmer and don't have much experience with
windows forms, any help is much appreciated. Thanks


Nov 15 '05 #3
here is a solution to my problem if anyone is interested

((Form1)NewsMyWay.Form1.ActiveForm).textBox1.Text= "Some text here";

On Sat, 31 Jan 2004 09:05:04 GMT, polarz <po****@hotmail.com> wrote:
Hello Max, thanks for the reply. When I try to use your code I get an
unspecified cast error. I see the logic of your code but I can't get
it to work. I have the class in a different file named Class2.cs, but
it's in the same namespace. Here is how I have my code.

class someData : System.ApplicationException //this is in Class2.cs
{
public void ShowMyData(NewsMyWay.Form1 form)
{
form.textBox1.Text = "Some Stuff Here";
}
}

private void button2_Click(object sender, System.EventArgs e)
{
someData sd = new someData();
Form1 theForm = (Form1) sender;
sd.ShowMyData(theForm);

}

Basicly I'm trying to alter a textBox and a DataGrid from another
class and am having trouble with both. I'm sure this is a simple
solution but I can't see it :/

On Fri, 30 Jan 2004 03:53:01 -0800, "Max Guernsey"
<ma**********@harbingersoftware.com> wrote:

I'm not sure I understand your problem completely. I'm going to do
the best
I can...

... are you looking for something like the following?

#region Example code
public class SomeData : SomeOtherClassHere {
public void ShowData(Form1 form) {
Form1.textBox1.Text = "Some Stuff Here";
}
}

public class Form1 {
...
private void button2_Click(object sender, System.EventArgs e) {
SomeData sd = new SomeData();
Form1 theForm = (Form1) sender;
sd.ShowData(theForm);
}
#endregion

That will create a class named SomeData whose instances have a method
that
can effect an instance of the Form1 class in such a way as to modify
the
Text property of their textBox1 field.

Is that what you wanted? If not, please clarify.

Thank you,
Max Guernsey
http://www.harbingersoftware.com

"polarz" <po****@hotmail.com> wrote in message
news:qa********************************@4ax.com.. .
I'm having trouble getting items from different classes to display in
my textBox.

e.g.

private void button2_Click(object sender, System.EventArgs e)
{
someData sd = new someData();
sd.showData();
}

class someData : Form1
{
public void showData()
{
textBox1.Text="Some Stuff Here";
}
}

nothing shows up in the textBox when I press the button

I also tried

class someData : SomeOtherClassHere
{
public void showData()
{
Form1 f = new Form1();
f.textBox1.Text="Some Complete BS Here";
}
}

which is what I'd like to do, use a form that uses a class other than
Form1

I'm a pretty new programmer and don't have much experience with
windows forms, any help is much appreciated. Thanks


Nov 15 '05 #4

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

Similar topics

5
by: Park | last post by:
In the multiple line textbox, is it possible that every sentences shows different color ? For example, test sentence 1 : red test sentence 2 : blue ....
3
by: Lian | last post by:
Hi everybody I have a problem .I have a textbox although the TextMode property is multyline I can't write in a several rows What can I do? tnx lian
10
by: liups | last post by:
Hi, I have a multi-line textbox that accepts text input, I want it to adjust its height according to the text it holds, so I use a SendMessage API to get the line count of the text, then set the...
2
by: shal | last post by:
hello I am trying to change text color of the textbox1 from another form named Form2. i am using following code right now but it doesnt change property of textbox1. can you tell me whats wrong...
7
by: Andrew McKendrick | last post by:
Hi, I've noticed a bug in VB.NET (latest .NET Framework)... - I have a TabControl on a form with several tabs. - Each tab contains text boxes that are bound to fields in a data source...
2
by: jason | last post by:
hello. i am just trying to save a TextBox.Text value to a database, but strangely, when the value is changed on the web form, the changes are not recognized in the event where i try to save the...
4
by: Ken Soenen | last post by:
The code below illustrates my problem which is: I'm trying to access the TEXT from TextBox1 which is on Form1. Line "aa = Form1.TextBox1.Text" produces the error--Reference to a non-shared member...
2
by: moumita | last post by:
I have the folowing code..the logic according to me is correct..but I dont know...the msg boxes are not displaying anything...am I supposed to change any settings ??? Public Class Form1
4
by: aurora10 | last post by:
Can ant body help me to see how to get access to all controls of the Form for Sub in a different class. Thanks in advance. this is how it looks: ////////////////////////////////////////...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
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...
1
isladogs
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...
0
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...
0
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
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....
0
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
0
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...

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.