943,982 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Unsolved
  • Views: 2891
  • C# RSS
Aug 27th, 2006
0

Accesing controls on the form from custom method

Expand Post »
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
Last edited by Stivi; Aug 27th, 2006 at 2:05 pm.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
Stivi is offline Offline
26 posts
since Jun 2005
Aug 28th, 2006
0

Re: Accesing controls on the form from custom method

Hi,

C# Syntax (Toggle Plain Text)
  1. void change(string s)
  2. {
  3. label1.Text = s;
  4. }
  5.  
  6. private void button1_Click(object sender, System.EventArgs e)
  7. {
  8. change("Hakan");
  9. }

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

Loren Soth
Reputation Points: 28
Solved Threads: 4
Posting Whiz in Training
Lord Soth is offline Offline
233 posts
since Mar 2006
Aug 28th, 2006
0

Re: Accesing controls on the form from custom method

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?
Reputation Points: 23
Solved Threads: 16
Posting Whiz in Training
plazmo is offline Offline
206 posts
since Aug 2005
Aug 28th, 2006
0

Re: Accesing controls on the form from custom method

Thanks Loren,

I've declared my method as:

public static 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
Reputation Points: 10
Solved Threads: 0
Light Poster
Stivi is offline Offline
26 posts
since Jun 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: improve events speed
Next Thread in C# Forum Timeline: firewall application





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC