Friends.
I'm developing a hangman game in C++ Winforms, practically ready, but it's giving an error that I couldn't solve. I want to create an array of Labels. This array has no fixed size. At the beginning of the program I put: static array<Label^>^ labels; To create the labels that will contain the letters of the word drawn, I developed the following snippet: It is giving the error Object reference not set to an instance of an object in line labels[i] = gcnew Label(); Thanks
void IniciarLabels()
{
tam = palavra->Length;
for (int i = 0; i < tam; i++)
{
labels[i] = gcnew Label();
labels[i]->Font = gcnew System::Drawing::Font("Arial", 26, FontStyle::Bold);
labels[i]->ForeColor = Color::Black;
labels[i]->TextAlign = ContentAlignment::MiddleLeft;
labels[i]->AutoSize = false;
labels[i]->Size = System::Drawing::Size(40, 40);
labels[i]->Text = palavra[i] == ' ' ? " " : "_";
labels[i]->Location = i == 0 ? System::Drawing::Point(X, Y + 5) : System::Drawing::Point((labels[i - 1]->Location.X + 43), Y + 5);
panel1->Controls->Add(labels[i]);
}
}