0

我在使用我的代碼時遇到了一些麻煩。我需要在文本框中顯示存儲在變量rawValue中的值。在文本框中寫入一個變量值,visual C++

這是一個重要的問題我的代碼的一部分:

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-> Text」之類的東西,但它不適用於我的代碼。

回答

1

從你的文章中,我認爲你有忽視大小寫的傾向。 C++區分大小寫;因此,文本和文本是不同的。您必須使用 - >範圍操作符來引用。 正確的語法:

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

我試過這個,但我不斷收到相同的錯誤消息。 – Bizzys

相關問題