0

I want to take the variable xx from another class (Class2) and set it equal to the variable mouseX from form1.cs.

Example code from form1.cs:

private void canvas_MouseClick(object sender, MouseEventArgs e)
    {
        mouseX = Cursor.Position.X;
        mouseY = Cursor.Position.Y;
        //I am thinking here I could do Class2.xx = mouseX in order to set the variable xx 
        // equal to the newly acquired mouseX value, but this is not the case
    }
Alexei Levenkov
  • 98,904
  • 14
  • 127
  • 179
  • Not enough information. Where is `mouseX` defined? Is something else changing it? What is `Class2`? What happens if you do `Class2.xx = mouseX`? Is something else changing `Class2.xx`? Why do you think “this is not the case”? Why are you splitting `Cursor.Position` into separate `mouseX` and `mouseY`? – Dour High Arch Nov 18 '17 at 03:50
  • First, you'll need to understand the difference between a class and a class instance (e.g., object). Is `xx` a static member of Class2? What exactly is Class2? Can you get an instance of Class2 in forms1? If you are new to programming, then this can be a bit of an advanced concept, but in general what you want to do (if I understand you correctly) can be accomplished in a number of different ways like using events or using callbacks, etc. It's best you find an example relevant to what you want to do and go from there. – realharry Nov 18 '17 at 03:51

0 Answers0