C
C#10mo ago
br0kE

❔ ✅ CS0116 [SOLVED]

and CS1061: 'Form1' does not contain a definition for 'button1_Click' and no accessible extension method 'button1_Click' accepting a first argument of type 'Form1' could be found (are you missing a using directive or a assembly reference?) I'm just making a installer and i'm a C# beginner so I don't know how to fix this
22 Replies
Angius
Angius10mo ago
Methods go into classes Classes go into namespaces Seems like your titular error is because some of your methods have been placed in a namespace
Angius
Angius10mo ago
This is sus in particular
Angius
Angius10mo ago
Make sure you format your code properly so you can see where each class and method starts and ends $prettycode
MODiX
MODiX10mo ago
To format your code in Visual Studio, Visual Studio Code, Rider, use the following shortcut:
Visual Studio CTRL + K + D
Rider / Resharper CTRL + ALT + L
Visual Studio Code SHIFT + ALT + F
Visual Studio CTRL + K + D
Rider / Resharper CTRL + ALT + L
Visual Studio Code SHIFT + ALT + F
NOTE: the first key must be held while doing it. https://cdn.discordapp.com/attachments/569261465463160900/899513918567890944/2021-10-18_01-26-35.gif
br0kE
br0kE10mo ago
I restarted VS 2019 and Main.Designer.cs changed so whats a methof d
Angius
Angius10mo ago
A function
br0kE
br0kE10mo ago
i just followed this tutorial then this happened https://www.youtube.com/watch?v=n5jDXRDg070
DM Velocity
YouTube
C# WinForm UI - Round Rect / Ellipse Button
This tutorial is to teach you how to make an ellipse button in C# without 3rd party app. #UIDesign #CSharp #Button For more videos please go to my channel: https://www.youtube.com/channel/UCCViFHnPq_IQV5eQTbjVu1A Music: https://www.youtube.com/watch?v=B7xai5u_tnk&list=RDMMcMg8KaMdDYo&index=2
br0kE
br0kE10mo ago
how do i know if the thing im looking at is a function
Angius
Angius10mo ago
$structure
MODiX
MODiX10mo ago
namespace Namespace;

[Attribute]
public class Class
{
public string PublicField;
private bool _privateField;
protected double protectedField;

public int PublicProperty { get; set; }

public Class() {} // Constructor

public void Method(int parameter)
{
var localVariable = parameter;
}
}
namespace Namespace;

[Attribute]
public class Class
{
public string PublicField;
private bool _privateField;
protected double protectedField;

public int PublicProperty { get; set; }

public Class() {} // Constructor

public void Method(int parameter)
{
var localVariable = parameter;
}
}
For C# versions older than 10, see $StructureOld
Angius
Angius10mo ago
Here's the basic structore of a C# file
br0kE
br0kE10mo ago
i dont understand 💀
Angius
Angius10mo ago
Which part?
br0kE
br0kE10mo ago
$StructureOld i think i have an older version of C#
MODiX
MODiX10mo ago
namespace Namespace
{
[Attribute]
public class Class
{
public string PublicField;
private bool _privateField;
protected double protectedField;

public int PublicProperty { get; set; }

public Class() {} // Constructor

public void Method(int parameter)
{
var localVariable = parameter;
}
}
}
namespace Namespace
{
[Attribute]
public class Class
{
public string PublicField;
private bool _privateField;
protected double protectedField;

public int PublicProperty { get; set; }

public Class() {} // Constructor

public void Method(int parameter)
{
var localVariable = parameter;
}
}
}
For C# versions from 10 onwards, see $structure
br0kE
br0kE10mo ago
idfk man maybe both
Angius
Angius10mo ago
This example shows most of what can be in a file, but not everything has to be there The stripped down version would be
namespace Namespace
{
public class Class
{
public void Method()
{

}
}
}
namespace Namespace
{
public class Class
{
public void Method()
{

}
}
}
So, in short, make sure that - Your class is within the namespaces braces ({}) or make sure the namespace is file-scoped, so ends with a semicolon (;) and doesn't have braces - All your methods are within the class's braces Prettyinfying your code will help you see whether or not everything is correct It's easier to spot the error when your code isn't
class Animal
{
public void Bark() {

}
}
}
class Animal
{
public void Bark() {

}
}
}
but
class Animal
{
public void Bark()
{

}
}
}
class Animal
{
public void Bark()
{

}
}
}
instead You immediately see you have one } too many
br0kE
br0kE10mo ago
well deleting that } solved the problem thanks cs0161 is also fixed
Denis
Denis10mo ago
$close
MODiX
MODiX10mo ago
Use the /close command to mark a forum thread as answered
br0kE
br0kE10mo ago
didnt know there was a close command
Accord
Accord10mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.