0

Hi,

Here's what I've got:
Visual Studio 2005
C# Application with form and a label on it
(This is a simplified project ;) )

Here's what I'd like to do:
I want to change text on the label from the method I'll create. Looks simple... If I'll create a button which will change a label's text, it works. But if I want to change it from method I've created on my own, it's impossible... I just don't see any label in my method... Is there some way to access it?

Thanks, Steve

3
Contributors
3
Replies
4
Views
11 Years
Discussion Span
Last Post by Stivi
0

Hi,

void change(string s)
{
  label1.Text = s;
}

private void button1_Click(object sender, System.EventArgs e)
{
  change("Hakan");
}

As you see you have to call your own method from somewhere.

Loren Soth

0

If you cant see your label, you may have created the new method in a different class as your form. Did you make a new cs file?

0

Thanks Loren,

I've declared my method as:

[B]public static [/B]void change(string s)
{
  label1.Text = s;
}

and because of that I was unable to use label1 :rolleyes: . I've tried to declare it as void only and it works...

So thanx a lot,
Steve

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.