Error CS0117

ad.txt

Member
Joined
Oct 4, 2022
Messages
17
Programming Experience
Beginner
Hi !

I've written this code :


C#:
private void button1_Click(object sender, EventArgs e)
{
    var label = Label.Open("LargeAdresstestLabel.label");
    label.SetObjectText("lblFirstName", label 24);
}

But I have an error saying that :" 'Label' doesn't contain a definiton for 'Open' ".

Do you know how to resolve this error ?

Thank you for your help
 
Given that that code is in the Click event handler of a Button, this is presumably a Windows Forms app. In that case, your use of Label is most likely being interpreted as the System.Windows.Forms.Label class and it is looking for a static method of that class. What do you think Label should be interpreted as there? You may need to fully qualify the type name or provide an alias.
 
Use a fully qualified name for your Label class with the namespace. For example, SomeCompany.Product.Label assuming that the class in in the SameCompany.Product namespace. What namespace is your Label class in?
 
Can I use any other word than Label ?
Is this your own class? You probably shouldn't name it Label in the first place. What does it actually represent? If you change the name of that class then there's no name clash. If you must or want to keep that name then, as I said, you can fully qualify the name where you use it, as demonstrated above, or else you can create an alias, which requires fully qualifying the name once, e.g.
C#:
using lbl = SomeCompany.Product.Label;
You can then use the alias in place of the fully-qualified type name.
 
If our OP was following along with the blog post linked below, he should have noted that the blog post was suggesting using WPF or WinRT app, not WinForms. If he had followed that, then there would have been no name collision.

 
If our OP was following along with the blog post linked below, he should have noted that the blog post was suggesting using WPF or WinRT app, not WinForms. If he had followed that, then there would have been no name collision.

Yes that's where I found the code I'm using, I was just wondering if it would work on WinForm.
Is there any alternative to make it work on WinForm ?
 
Back
Top Bottom