0

I have a 2-dimensional array to create a button in class Form1.

for (int LocationX = 0; LocationX < 9; LocationX++)
{
 for (int LocationY = 0; LocationY < 9; LocationY++)
 {
  setButton[LocationX, LocationY] = new MakeButton();
  setButton[LocationX, LocationY].Location = new System.Drawing.Point(LocationX * 30, LocationY * 30);

  setButton[LocationX, LocationY].Size = new System.Drawing.Size(30, 30);
  this.Controls.Add(setButton[LocationX, LocationY]);
 }
}

I want to trigger 1 button with a specific address in another class. It looks like class B:

{
 if() 
 {
  setButton[<location X i want open>, <location Y i want open>].Open();
  // but setButton not exist
 }
}
fatihyildizhan
  • 8,614
  • 7
  • 64
  • 88
SomeOne
  • 1
  • 3
  • 1
    You need a reference to the Form1 object in class B. – Klaus Gütter Apr 30 '21 at 04:59
  • There is only limited info in the question. But, you can make the setButton as a public property and use it in the other class. Use this answer https://stackoverflow.com/a/46570032/9522887 – Kishan Vaishnav Apr 30 '21 at 06:21
  • The question is quite vague, and addressing it completely involves a number of different problems to solve. See duplicate for the most important one though, i.e. how your classes should interact with each other. If you need more help, post one or more _specific_ questions that include a proper [mcve], along with a detailed explanation of what that code does, how that's different from what you want, and what specifically you need help with. – Peter Duniho Apr 30 '21 at 06:26

0 Answers0