Click here to Skip to main content
       

Managed C++/CLI

 
GeneralRe: C++ CLR Windows Form Application (Printing to the Printer) Pinmembereakteam15-Apr-13 6:00 
GeneralRe: C++ CLR Windows Form Application (Printing to the Printer) Pinmemberkklim26-Aug-13 23:07 
GeneralRe: C++ CLR Windows Form Application (Printing to the Printer) PinmvpRichard MacCutchan27-Aug-13 3:47 
GeneralRe: C++ CLR Windows Form Application (Printing to the Printer) Pinmemberkklim27-Aug-13 18:40 
GeneralRe: C++ CLR Windows Form Application (Printing to the Printer) PinmvpRichard MacCutchan27-Aug-13 20:51 
GeneralRe: C++ CLR Windows Form Application (Printing to the Printer) Pinmemberkklim27-Aug-13 22:47 
GeneralRe: C++ CLR Windows Form Application (Printing to the Printer) PinmvpRichard MacCutchan27-Aug-13 22:55 
GeneralRe: C++ CLR Windows Form Application (Printing to the Printer) Pinmemberkklim29-Aug-13 18:49 
QuestionC++ and xaml connection to access database code Pinmemberjuma owori10-Apr-13 23:34 
AnswerRe: C++ and xaml connection to access database code PinmvpRichard MacCutchan11-Apr-13 0:48 
Questionconversion from tchar* to string^ Pinmemberraghunath sahoo3-Apr-13 4:38 
AnswerRe: conversion from tchar* to string^ PinmemberThePhantomUpvoter3-Apr-13 5:13 
AnswerRe: conversion from tchar* to string^ PinmvpRichard MacCutchan3-Apr-13 5:13 
QuestionCreating a global array of labels at runtime PinmemberDouglas Kirk31-Mar-13 11:30 
I have an old Borland C++ project that displayed a 16 x 16 group of labels displaying 0x00 to 0xFF for the purpose of diagnostics.
 
I am now using MicroSoft Visual Studio 2010 C++
 
I am having a problem creating an array of labels at runtime that the labels are accessable by other routines such as a timer interval routine
 
 
#pragma once
#include <stdio.h>

namespace SerialTester {
 
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
 
/// <summary>
/// Summary for Form1

int count;
int tindex;
    
 
/// </summary>
public ref class Form1 : public System::Windows::Forms::Form
{
public:
        
    Form1(void)
    {
      InitializeComponent();
      count = 0;
      tindex = 0;
      char buffer[200];
      array< Label ^ > ^ labels;
      labels = gcnew array<Label^>(256);
 
      for (int index = 0; index < 256; ++index) 
      {
         Label ^ label = gcnew Label;
         label->Size = System::Drawing::Size(25, 25);
         label->Name = "C" + index;
         sprintf(buffer,"%2X",index);
         label->Text = Convert::ToString( index, 16 ); 
 
         String^ clistr = gcnew String(buffer);
         //label->Text = clistr; //buffer;
         Controls->Add(label);
         labels[index] = label;
      }
      //
      //TODO: Add the constructor code here
      //
    }
 
    protected:
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        ~Form1()
        {
            if (components)
            {
                delete components;
            }
        }
    private: System::Windows::Forms::Label^  label1;
    private: System::Windows::Forms::Panel^  panel1;
    private: System::Windows::Forms::Timer^  timer1;
    private: System::ComponentModel::IContainer^  components;
    protected: 
 
    private:
    /// <summary>
    /// Required designer variable.
    /// </summary>

 
#pragma region Windows Form Designer generated code
    /// <summary>
    /// Required method  do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    void InitializeComponent(void)
    {
      this->components = (gcnew System::ComponentModel::Container());
      this->label1 = (gcnew System::Windows::Forms::Label());
      this->panel1 = (gcnew System::Windows::Forms::Panel());
      this->timer1 = (gcnew System::Windows::Forms::Timer(this->components));
      this->SuspendLayout();
      // 
      //
      this->Controls->Add(this->panel1);
      this->Controls->Add(this->label1);
      this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
      this->ResumeLayout(false);
   }
 
#pragma endregion
    private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
             }
    private: System::Void label1_Click(System::Object^  sender, System::EventArgs^  e) {
                 count++;
                 label1->Text = Convert::ToString( count, 10 );
                
             }
    private: System::Void panel1_Paint(System::Object^  sender, System::Windows::Forms::PaintEventArgs^  e) {
             }
 

 
private: System::Void timer1_Tick(System::Object^  sender, System::EventArgs^  e) 
{
 labels[tindex++]->BackColor = System::Drawing::Color::SkyBlue;
 tindex%=256;
}
};
}
 

 
 

So when I create the form I created an array of 256 Labels at runtime, labels[x] but in the timer1_Tick I can not access them because the array is not global.
 
QUESTION: How can I do this, should my creation be somewheres else so that it is global.
 
QUESTION: in my Borland project I simply used sprintf to format the caption of each label to 00 .. FF, but can not seem to format the text simply in upper case.
 
Any help from anyone would be greatly appriciated.
 
Or a link to a tutorial on this.
 
Thank you in advance
Douglas
AnswerRe: Creating a global array of labels at runtime PinmemberThePhantomUpvoter31-Mar-13 14:10 
GeneralRe: Creating a global array of labels at runtime PinmemberDouglas Kirk31-Mar-13 14:38 
GeneralRe: Creating a global array of labels at runtime PinmemberThePhantomUpvoter31-Mar-13 15:22 
GeneralRe: Creating a global array of labels at runtime PinmemberDouglas Kirk31-Mar-13 15:56 
GeneralRe: Creating a global array of labels at runtime PinmemberThePhantomUpvoter31-Mar-13 16:26 
QuestionPassing a C# string to C++/CLI does not show up from a CPP program Pinmembersujayg26-Mar-13 0:24 
AnswerRe: Passing a C# string to C++/CLI does not show up from a CPP program PinmemberDavid Knechtges26-Mar-13 8:50 
GeneralRe: Passing a C# string to C++/CLI does not show up from a CPP program Pinmembersujayg26-Mar-13 21:33 
AnswerRe: Passing a C# string to C++/CLI does not show up from a CPP program PinmvpRichard MacCutchan26-Mar-13 22:59 
GeneralRe: Passing a C# string to C++/CLI does not show up from a CPP program Pinmembersujayg27-Mar-13 3:54 
GeneralRe: Passing a C# string to C++/CLI does not show up from a CPP program PinmvpRichard MacCutchan27-Mar-13 3:58 
GeneralRe: Passing a C# string to C++/CLI does not show up from a CPP program Pinmembersujayg27-Mar-13 4:11 
GeneralRe: Passing a C# string to C++/CLI does not show up from a CPP program PinmvpRichard MacCutchan27-Mar-13 4:19 
GeneralRe: Passing a C# string to C++/CLI does not show up from a CPP program Pinmembersujayg27-Mar-13 4:52 
GeneralRe: Passing a C# string to C++/CLI does not show up from a CPP program PinmvpRichard MacCutchan27-Mar-13 5:03 
GeneralRe: Passing a C# string to C++/CLI does not show up from a CPP program Pinmembersujayg29-Mar-13 19:09 
GeneralRe: Passing a C# string to C++/CLI does not show up from a CPP program PinmvpRichard MacCutchan29-Mar-13 23:00 
AnswerRe: Passing a C# string to C++/CLI does not show up from a CPP program Pinmemberjschell30-Mar-13 13:33 
QuestionDidn't Understand to logic of calculation of this program.? PinmemberTaqi_Shah11-Mar-13 7:26 
AnswerRe: Didn't Understand to logic of calculation of this program.? PinmemberThePhantomUpvoter11-Mar-13 7:55 
SuggestionRe: Didn't Understand to logic of calculation of this program.? PinmemberMicroVirus13-Mar-13 12:16 
QuestionNeed Urgent Help!! PinmemberMember 933160011-Mar-13 2:18 
AnswerRe: Need Urgent Help!! PinmemberMarco Bertschi14-Mar-13 10:36 
Questionhow to call vcvarsall.bat with Process::Start method? Pinmemberaupres8-Mar-13 23:43 
AnswerRe: how to call vcvarsall.bat with Process::Start method? PinmemberThePhantomUpvoter9-Mar-13 3:06 
GeneralRe: how to call vcvarsall.bat with Process::Start method? Pinmemberaupres9-Mar-13 13:09 
AnswerRe: how to call vcvarsall.bat with Process::Start method? PinmvpRichard MacCutchan9-Mar-13 22:46 
Questioncandidate function not accessible Pinmemberbonosa1-Mar-13 17:35 
AnswerRe: candidate function not accessible PinmvpRichard MacCutchan2-Mar-13 0:01 
GeneralRe: candidate function not accessible Pinmemberbonosa2-Mar-13 7:59 
GeneralRe: candidate function not accessible PinmvpRichard MacCutchan2-Mar-13 9:13 
Questionsqrt() function strange behavouir PinmemberAmrit Agr28-Feb-13 23:44 
AnswerRe: sqrt() function strange behavouir PinmvpRichard MacCutchan1-Mar-13 0:56 
Questionbatch files PinmemberMember 981569020-Feb-13 22:42 
AnswerRe: batch files PinmvpRichard MacCutchan20-Feb-13 22:57 
GeneralRe: batch files PinmemberMember 981569020-Feb-13 23:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Advertise | Privacy | Mobile
Web04 | 2.8.140916.1 | Last Updated 10 Sep 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid