Click here to Skip to main content
12,819,913 members (33,172 online)

Managed C++/CLI

Questionconversion from tchar* to string^ Pin
raghunath sahoo3-Apr-13 5:38
memberraghunath sahoo3-Apr-13 5:38 
AnswerRe: conversion from tchar* to string^ Pin
ThePhantomUpvoter3-Apr-13 6:13
memberThePhantomUpvoter3-Apr-13 6:13 
AnswerRe: conversion from tchar* to string^ Pin
Richard MacCutchan3-Apr-13 6:13
mvpRichard MacCutchan3-Apr-13 6:13 
QuestionCreating a global array of labels at runtime Pin
Douglas Kirk31-Mar-13 12:30
memberDouglas Kirk31-Mar-13 12: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
      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;
         label->Text = Convert::ToString( index, 16 ); 

         String^ clistr = gcnew String(buffer);
         //label->Text = clistr; //buffer;
         labels[index] = label;
      //TODO: Add the constructor code here

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
            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;

    /// <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->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);

#pragma endregion
    private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
    private: System::Void label1_Click(System::Object^  sender, System::EventArgs^  e) {
                 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;

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
AnswerRe: Creating a global array of labels at runtime Pin
ThePhantomUpvoter31-Mar-13 15:10
memberThePhantomUpvoter31-Mar-13 15:10 
GeneralRe: Creating a global array of labels at runtime Pin
Douglas Kirk31-Mar-13 15:38
memberDouglas Kirk31-Mar-13 15:38 
GeneralRe: Creating a global array of labels at runtime Pin
ThePhantomUpvoter31-Mar-13 16:22
memberThePhantomUpvoter31-Mar-13 16:22 
GeneralRe: Creating a global array of labels at runtime Pin
Douglas Kirk31-Mar-13 16:56
memberDouglas Kirk31-Mar-13 16:56 
GeneralRe: Creating a global array of labels at runtime Pin
ThePhantomUpvoter31-Mar-13 17:26
memberThePhantomUpvoter31-Mar-13 17:26 
QuestionPassing a C# string to C++/CLI does not show up from a CPP program Pin
sujayg26-Mar-13 1:24
membersujayg26-Mar-13 1:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    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
Web02 | 2.8.170308.1 | Last Updated 5 Mar 2017
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid