By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,543 Members | 2,116 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,543 IT Pros & Developers. It's quick & easy.

displaying text from a different class into Form1.textBox1

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.