我知道这个问题之前已经被问过(很多次)但我似乎找不到答案。
我已经将一个 TestBox 拖到表单上,它
void InitializeComponent(void)
为我生成了方法中的代码。但是,当我添加此行时:
this->MyTextBox->Text = DateTime::Now.ToString();
打开设计器时出现标题错误?我的问题是,为什么会这样?以及如何摆脱它。
这是页面的完整代码:
#pragma once
namespace Project1 {
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 MyForm
/// </summary>
public ref class MyForm : public System::Windows::Forms::Form
{
public:
MyForm(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}
protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~MyForm()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::Label^ label1;
private: System::Windows::Forms::TextBox^ MyTextBox;
protected:
protected:
private:
/// <summary>
/// Required designer variable.
/// </summary>
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
//MAIN METHOD FOR FORM
void InitializeComponent(void)
{
this->label1 = (gcnew System::Windows::Forms::Label());
this->MyTextBox = (gcnew System::Windows::Forms::TextBox());
this->SuspendLayout();
//
// label1
//
this->label1->AutoSize = true;
this->label1->Location = System::Drawing::Point(132, 123);
this->label1->Name = L"label1";
this->label1->Size = System::Drawing::Size(75, 13);
this->label1->TabIndex = 0;
this->label1->Text = L"Callum Holden";
this->label1->Click += gcnew System::EventHandler(this, &MyForm::label1_Click);
//
// MyTextBox
//
this->MyTextBox->Location = System::Drawing::Point(54, 183);
this->MyTextBox->Name = L"MyTextBox";
this->MyTextBox->Size = System::Drawing::Size(100, 20);
this->MyTextBox->TabIndex = 1;
this->MyTextBox->Text = L"g" + DateTime::Now.ToString();
//
// MyForm
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(308, 275);
this->Controls->Add(this->MyTextBox);
this->Controls->Add(this->label1);
this->Name = L"MyForm";
this->Text = L"MyForm";
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
private: System::Void label1_Click(System::Object^ sender, System::EventArgs^ e) {
}
};
}
谢谢你的任何建议!,
卡勒姆