Click here to Skip to main content
15,891,033 members
Home / Discussions / Managed C++/CLI
   

Managed C++/CLI

 
GeneralRe: C++ CLR Windows Form Application (Printing to the Printer) Pin
Richard MacCutchan27-Aug-13 22:55
mveRichard MacCutchan27-Aug-13 22:55 
GeneralRe: C++ CLR Windows Form Application (Printing to the Printer) Pin
kklim29-Aug-13 18:49
kklim29-Aug-13 18:49 
QuestionC++ and xaml connection to access database code Pin
juma owori10-Apr-13 23:34
juma owori10-Apr-13 23:34 
AnswerRe: C++ and xaml connection to access database code Pin
Richard MacCutchan11-Apr-13 0:48
mveRichard MacCutchan11-Apr-13 0:48 
Questionconversion from tchar* to string^ Pin
raghunath sahoo3-Apr-13 4:38
raghunath sahoo3-Apr-13 4:38 
AnswerRe: conversion from tchar* to string^ Pin
NotPolitcallyCorrect3-Apr-13 5:13
NotPolitcallyCorrect3-Apr-13 5:13 
AnswerRe: conversion from tchar* to string^ Pin
Richard MacCutchan3-Apr-13 5:13
mveRichard MacCutchan3-Apr-13 5:13 
QuestionCreating a global array of labels at runtime Pin
Douglas Kirk31-Mar-13 11:30
Douglas 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

C++
#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 Pin
NotPolitcallyCorrect31-Mar-13 14:10
NotPolitcallyCorrect31-Mar-13 14:10 
GeneralRe: Creating a global array of labels at runtime Pin
Douglas Kirk31-Mar-13 14:38
Douglas Kirk31-Mar-13 14:38 
GeneralRe: Creating a global array of labels at runtime Pin
NotPolitcallyCorrect31-Mar-13 15:22
NotPolitcallyCorrect31-Mar-13 15:22 
GeneralRe: Creating a global array of labels at runtime Pin
Douglas Kirk31-Mar-13 15:56
Douglas Kirk31-Mar-13 15:56 
GeneralRe: Creating a global array of labels at runtime Pin
NotPolitcallyCorrect31-Mar-13 16:26
NotPolitcallyCorrect31-Mar-13 16:26 
QuestionPassing a C# string to C++/CLI does not show up from a CPP program Pin
SujayG26-Mar-13 0:24
SujayG26-Mar-13 0:24 
AnswerRe: Passing a C# string to C++/CLI does not show up from a CPP program Pin
David Knechtges26-Mar-13 8:50
David Knechtges26-Mar-13 8:50 
GeneralRe: Passing a C# string to C++/CLI does not show up from a CPP program Pin
SujayG26-Mar-13 21:33
SujayG26-Mar-13 21:33 
AnswerRe: Passing a C# string to C++/CLI does not show up from a CPP program Pin
Richard MacCutchan26-Mar-13 22:59
mveRichard MacCutchan26-Mar-13 22:59 
GeneralRe: Passing a C# string to C++/CLI does not show up from a CPP program Pin
SujayG27-Mar-13 3:54
SujayG27-Mar-13 3:54 
GeneralRe: Passing a C# string to C++/CLI does not show up from a CPP program Pin
Richard MacCutchan27-Mar-13 3:58
mveRichard MacCutchan27-Mar-13 3:58 
GeneralRe: Passing a C# string to C++/CLI does not show up from a CPP program Pin
SujayG27-Mar-13 4:11
SujayG27-Mar-13 4:11 
GeneralRe: Passing a C# string to C++/CLI does not show up from a CPP program Pin
Richard MacCutchan27-Mar-13 4:19
mveRichard MacCutchan27-Mar-13 4:19 
GeneralRe: Passing a C# string to C++/CLI does not show up from a CPP program Pin
SujayG27-Mar-13 4:52
SujayG27-Mar-13 4:52 
GeneralRe: Passing a C# string to C++/CLI does not show up from a CPP program Pin
Richard MacCutchan27-Mar-13 5:03
mveRichard MacCutchan27-Mar-13 5:03 
GeneralRe: Passing a C# string to C++/CLI does not show up from a CPP program Pin
SujayG29-Mar-13 19:09
SujayG29-Mar-13 19:09 
GeneralRe: Passing a C# string to C++/CLI does not show up from a CPP program Pin
Richard MacCutchan29-Mar-13 23:00
mveRichard MacCutchan29-Mar-13 23:00 

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.