Thread: Two-Dimensional Array of Labels

  1. #1
    Registered User
    Join Date
    Apr 2011
    Posts
    1

    Two-Dimensional Array of Labels

    Hi, I'm taking a college course in C++ so my experience is rather limited. I'm trying to create a two-dimensional array of labels. I'm using the following code but the labels do not show on the form:

    private: array<System::Windows::Forms::Label^> ^LabelArr;
    ..........
    void InitializeComponent(void)
    {....
    this->LabelArr = gcnew array<System::Windows::Forms::Label^>(40);
    for (int x = 0; x < 3; x++)
    {
    this->LabelArr[x]=(gcnew System::Windows::Forms::Label());
    this->LabelArr[x]->Visible = true;
    this->LabelArr[x]->Enabled = true;
    this->LabelArr[x]->AutoSize = true;
    this->LabelArr[x]->BackColor = System:rawing::Color::Red;
    this->LabelArr[x]->Location = System:rawing::Point(29*x, 13*x);
    this->LabelArr[x]->Name = L"LabelArr";
    this->LabelArr[x]->Size = System:rawing::Size(29, 13);
    this->LabelArr[x]->TabIndex = 0;
    this->LabelArr[x]->Text = L"label";

    }
    .....


    Also, I can't look at my form withou running the program.

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    This is C++/CLI, which is not the same language as C++.

    There's nothing two-dimensional about your array, either. And as far as I can see, you're never adding the labels you create to the parent component, e.g. by calling this->Add(this->LabelArr[x]).

    As for why you can't look at the form, I don't know. Perhaps the Forms designed doesn't work for C++/CLI. You could always write it in C# - if your "college course on C++" doesn't actually teach C++, what difference would it make?
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. two dimensional array
    By rondel in forum C Programming
    Replies: 1
    Last Post: 03-06-2010, 03:36 PM
  2. Array of Runtime Labels
    By wbeasl in forum C# Programming
    Replies: 3
    Last Post: 12-20-2008, 11:53 PM
  3. Replies: 24
    Last Post: 11-11-2008, 01:39 PM
  4. Two dimensional array
    By George2 in forum C Programming
    Replies: 3
    Last Post: 11-10-2007, 05:27 AM
  5. Replies: 1
    Last Post: 04-25-2006, 12:14 AM

Tags for this Thread