I’ve declared a few int
variables inside public partial class Form1 : Form
in C#. However, i can’t use or change them if it isn’t done inside a function (e. g. inside of private void button1_click
), as if the variables never existed. It gives a “”IDE1007: The name ‘r’ does not exist in the current context” error when trying to change tha value of r
. That said, I can’t create a pen using Pen dot = new Pen(Color.FromArgb(r, g, b));
, trying to do so gives another error, “CS0236: A field initializer cannot reference the nonstatic field, method, or property from “Form1.r”” (I’m trying to make a sort of MS Paint clone).
Here’s a snippet from my code:
int r = 0;
int g = 0;
int b = 0;
int size = 2;
Pen dot = new Pen(Color.FromArgb(r, g, b));
Pen rect = new Pen(Color.FromArgb(r, g, b));
Pen pencil = new Pen(Color.FromArgb(r, g, b));
string curpen = "";
Here are some screenshots with the errors:
enter image description here
enter image description here
Tried updating VS. Didn’t help. Any ideas?