Doron Muzar
Doron Muzar

Reputation: 443

How do i pass the Label4.Text to a new class?

In form1 i did:

public static Label lbl4(Label lbl) {
    Label lbl4 = lbl;
    return lbl4;
}

Then in Form1 i use it as:

lbl4(label4);

Then in the new class i use it:

Local(webSites, Form1.lbl4);

In the new class the method Local should accept: List , string The problem is to get the Label4 in form1 text.

The errors i get in the new class are:

Error 12 Argument 2: cannot convert from 'method group' to 'string'

Error 11 The best overloaded method match for 'GatherLinks.WebCrawler.Local(System.Collections.Generic.List, string)' has some invalid arguments

Both on the same line: Local(webSites, Form1.lbl4);

Upvotes: 0

Views: 145

Answers (3)

Millie Smith
Millie Smith

Reputation: 4604

You defined lbl4 to be a method. How is it supposed to know you want a Label?

A Label is also not a string.

Local(webSites, Form1.MyLabel.Text);

Also, the method lbl4 just returns its parameter. If you want to set text:

public void setLabelText(string text)
{
    MyLabel.Text = text;
}

Upvotes: 2

Yosi Dahari
Yosi Dahari

Reputation: 7009

Your code is fundamentally broken.

As for your error - you are passing Form1.lbl4 which isn't of type string. You should pass to Local method the Text property of the label.

Upvotes: 0

ohmusama
ohmusama

Reputation: 4215

There are a bunch of things wrong, and I will highlight some articles to go read

This one is on variable scope: http://msdn.microsoft.com/en-us/library/aa691132(v=vs.71).aspx

This one is on class variables: http://msdn.microsoft.com/en-us/library/vstudio/ms173109.aspx

This one is on static: http://msdn.microsoft.com/en-us/library/98f28cdx.aspx

This one is on Methods: http://msdn.microsoft.com/en-us/library/ms173114.aspx

Long story short, your function doesn't set anything, and when you try to use it later, you are not calling it, but instead it looks like you are expecting it to be a class variable because you called it previously.

Upvotes: 0

Related Questions