在文本框中编写变量值,visual C ++

时间:2012-09-19 18:29:53

标签: visual-studio-2010 visual-c++ textbox variable-assignment

我的代码遇到了一些麻烦。我需要在文本框中显示存储在变量 rawValue 中的值。

这是我的代码中与问题相关的部分:

public ref class Form1 : public System::Windows::Forms::Form
{
public:
    Form1(void)
    {
        InitializeComponent();
        //
        //TODO: Add the constructor code here
        //
    }

protected:
    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    ~Form1()
    {
        if (components)
        {
            delete components;
        }
    }
private: System::Windows::Forms::Button^  IniciarCaptura;
private: System::Windows::Forms::DataVisualization::Charting::Chart^  chart1;
private: System::Windows::Forms::Label^  label1;
private: System::Windows::Forms::Label^  label2;
private: System::Windows::Forms::Label^  label3;
private: System::Windows::Forms::TextBox^  textBoxRAW;
private: System::Windows::Forms::TextBox^  textBoxAtencao;
private: System::Windows::Forms::TextBox^  textBoxMeditacao;



protected: 

private:
    /// <summary>
    /// Required designer variable.
    /// </summary>
    System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    void InitializeComponent(void)
    {
        System::Windows::Forms::DataVisualization::Charting::ChartArea^  chartArea1 = (gcnew System::Windows::Forms::DataVisualization::Charting::ChartArea());
        System::Windows::Forms::DataVisualization::Charting::Legend^  legend1 = (gcnew System::Windows::Forms::DataVisualization::Charting::Legend());
        System::Windows::Forms::DataVisualization::Charting::Series^  series1 = (gcnew System::Windows::Forms::DataVisualization::Charting::Series());
        this->IniciarCaptura = (gcnew System::Windows::Forms::Button());
        this->chart1 = (gcnew System::Windows::Forms::DataVisualization::Charting::Chart());
        this->label1 = (gcnew System::Windows::Forms::Label());
        this->label2 = (gcnew System::Windows::Forms::Label());
        this->label3 = (gcnew System::Windows::Forms::Label());
        this->textBoxRAW = (gcnew System::Windows::Forms::TextBox());
        this->textBoxAtencao = (gcnew System::Windows::Forms::TextBox());
        this->textBoxMeditacao = (gcnew System::Windows::Forms::TextBox());
        (cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->chart1))->BeginInit();
        this->SuspendLayout();
        // 
        // IniciarCaptura
        // 
        this->IniciarCaptura->Location = System::Drawing::Point(15, 443);
        this->IniciarCaptura->Name = L"IniciarCaptura";
        this->IniciarCaptura->Size = System::Drawing::Size(75, 23);
        this->IniciarCaptura->TabIndex = 0;
        this->IniciarCaptura->Text = L"Iniciar";
        this->IniciarCaptura->UseVisualStyleBackColor = true;
        this->IniciarCaptura->Click += gcnew System::EventHandler(this, &Form1::IniciarCaptura_Click);
        // 
        // chart1
        // 
        chartArea1->Name = L"ChartArea1";
        this->chart1->ChartAreas->Add(chartArea1);
        legend1->Name = L"Legend1";
        this->chart1->Legends->Add(legend1);
        this->chart1->Location = System::Drawing::Point(15, 99);
        this->chart1->Name = L"chart1";
        series1->ChartArea = L"ChartArea1";
        series1->Legend = L"Legend1";
        series1->Name = L"Series1";
        this->chart1->Series->Add(series1);
        this->chart1->Size = System::Drawing::Size(300, 300);
        this->chart1->TabIndex = 1;
        this->chart1->Text = L"chart1";
        // 
        // label1
        // 
        this->label1->AutoSize = true;
        this->label1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 8.25F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point, 
            static_cast<System::Byte>(0)));
        this->label1->Location = System::Drawing::Point(12, 13);
        this->label1->Name = L"label1";
        this->label1->Size = System::Drawing::Size(36, 13);
        this->label1->TabIndex = 2;
        this->label1->Text = L"RAW";
        // 
        // label2
        // 
        this->label2->AutoSize = true;
        this->label2->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 8.25F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point, 
            static_cast<System::Byte>(0)));
        this->label2->Location = System::Drawing::Point(12, 40);
        this->label2->Name = L"label2";
        this->label2->Size = System::Drawing::Size(54, 13);
        this->label2->TabIndex = 3;
        this->label2->Text = L"Atenção";
        // 
        // label3
        // 
        this->label3->AutoSize = true;
        this->label3->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 8.25F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point, 
            static_cast<System::Byte>(0)));
        this->label3->Location = System::Drawing::Point(12, 69);
        this->label3->Name = L"label3";
        this->label3->Size = System::Drawing::Size(66, 13);
        this->label3->TabIndex = 4;
        this->label3->Text = L"Meditação";
        // 
        // textBoxRAW
        // 
        this->textBoxRAW->Location = System::Drawing::Point(78, 5);
        this->textBoxRAW->Name = L"textBoxRAW";
        this->textBoxRAW->Size = System::Drawing::Size(355, 20);
        this->textBoxRAW->TabIndex = 5;
        this->textBoxRAW->TextChanged += gcnew System::EventHandler(this, &Form1::textBoxRAW_TextChanged);
        // 
        // textBoxAtencao
        // 
        this->textBoxAtencao->Location = System::Drawing::Point(78, 33);
        this->textBoxAtencao->Name = L"textBoxAtencao";
        this->textBoxAtencao->Size = System::Drawing::Size(355, 20);
        this->textBoxAtencao->TabIndex = 6;
        // 
        // textBoxMeditacao
        // 
        this->textBoxMeditacao->Location = System::Drawing::Point(78, 62);
        this->textBoxMeditacao->Name = L"textBoxMeditacao";
        this->textBoxMeditacao->Size = System::Drawing::Size(355, 20);
        this->textBoxMeditacao->TabIndex = 7;
        // 
        // Form1
        // 
        this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
        this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
        this->ClientSize = System::Drawing::Size(448, 484);
        this->Controls->Add(this->textBoxMeditacao);
        this->Controls->Add(this->textBoxAtencao);
        this->Controls->Add(this->textBoxRAW);
        this->Controls->Add(this->label3);
        this->Controls->Add(this->label2);
        this->Controls->Add(this->label1);
        this->Controls->Add(this->chart1);
        this->Controls->Add(this->IniciarCaptura);
        this->Name = L"Form1";
        this->Text = L"Form1";
        (cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->chart1))->EndInit();
        this->ResumeLayout(false);
        this->PerformLayout();

    }
#pragma endregion
static void handleDataValueFunc(unsigned char extendedCodeLevel, unsigned char code,
    unsigned char valueLength, const unsigned char *value, void *customData)
{
    /*FILE *arq1;
    FILE *arq2;
    FILE *arq3;
        arq1 = fopen("raw.txt","a");
        arq2 = fopen("atencao.txt","a");
        arq3 = fopen("meditacao.txt","a");*/

    if (extendedCodeLevel == 0 && code == RAW_WAVE_CODE)
    {
        short rawValue = ((value[0] << 8) & 0xff00) | (0x00ff & value[1]);
        /*printf("%d\n", rawValue);
        fprintf(arq1,"%d\n",rawValue);*/

        textBoxRAW.SetWindowText(textBoxRAW.text + "" + rawValue + " ");
    }    

我收到以下错误:

error C2228: left of '.Text' must have class/struct/union

这是错误来自的行:

textBoxRAW.SetWindowText(textBoxRAW.text + "" + rawValue + " ");

我该如何解决这个问题?我已经看过代码的例子,人们只会写一些类似“TextBox-&gt; Text”的内容,但它对我的代码不起作用。

1 个答案:

答案 0 :(得分:1)

从你的帖子中,我认为你倾向于忽视案例。 C ++区分大小写;因此,文字和文字是不同的。你必须使用 - &gt;范围运算符用于引用。 正确的语法:

    textBoxRAW->Text  = textBoxRAW->Text  + " " + rawValue + " ";