CLR!?高手进,看一什么启用CLR
#using <System.dll>#using <System.Drawing.dll>
#using <System.Windows.Forms.dll>
using namespace System;
using namespace System::Collections::Generic;
using namespace System::ComponentModel;
using namespace System::Drawing;
using namespace System::Text;
using namespace System::Windows::Forms;
using namespace std;
// This sample demonstrates the use of the
// DesignerSerializationVisibility attribute
// to serialize a collection of strings
// at design time.
namespace SerializationDemo
{
public ref class SerializationDemoControl :
public System::Windows::Forms::UserControl
{
// This is the TextBox contained by
// the SerializationDemoControl.
private:
System::Windows::Forms::TextBox^ demoControlTextBox;
// This field backs the Strings property.
private:
array<String^>^ stringsValue;
public:
SerializationDemoControl()
{
InitializeComponent();
stringsValue = gcnew array<String^>(1);
}
// When the DesignerSerializationVisibility attribute has
// a value of "Content" or "Visible" the designer will
// serialize the property. This property can also be edited
// at design time with a CollectionEditor.
public:
[DesignerSerializationVisibility(
DesignerSerializationVisibility::Content)]
property array<String^>^ Strings
{
array<String^>^ get()
{
return this->stringsValue;
}
void set(array<String^>^ value)
{
this->stringsValue = value;
// Populate the contained TextBox with the values
// in the stringsValue array.
StringBuilder^ sb =
gcnew StringBuilder(this->stringsValue->Length);
for (int i = 0; i < this->stringsValue->Length; i++)
{
sb->Append(this->stringsValue[i]);
sb->Append(Environment::NewLine);
}
this->demoControlTextBox->Text = sb->ToString();
}
}
private:
void InitializeComponent()
{
this->demoControlTextBox =
gcnew System::Windows::Forms::TextBox();
this->SuspendLayout();
// Settings for the contained TextBox control.
this->demoControlTextBox->AutoSize = false;
this->demoControlTextBox->Dock =
System::Windows::Forms::DockStyle::Fill;
this->demoControlTextBox->Location =
System::Drawing::Point(5, 5);
this->demoControlTextBox->Margin =
System::Windows::Forms::Padding(0);
this->demoControlTextBox->Multiline = true;
this->demoControlTextBox->Name = "textBox1";
this->demoControlTextBox->ReadOnly = true;
this->demoControlTextBox->ScrollBars = ScrollBars::Vertical;
this->demoControlTextBox->Size =
System::Drawing::Size(140, 140);
this->demoControlTextBox->TabIndex = 0;
// Settings for SerializationDemoControl.
this->Controls->Add(this->demoControlTextBox);
this->Name = "SerializationDemoControl";
this->Padding = System::Windows::Forms::Padding(5);
this->ResumeLayout(false);
}
};
public ref class SerializationDemoForm :
public System::Windows::Forms::Form
{
SerializationDemoControl^ serializationDemoControl;
public:
SerializationDemoForm()
{
InitializeComponent();
serializationDemoControl = nullptr;
}
// The Windows Forms Designer emits code to this method.
// If an instance of SerializationDemoControl is added
// to the form, the Strings will be serialized here.
private:
void InitializeComponent()
{
this->serializationDemoControl =
gcnew SerializationDemo::SerializationDemoControl();
this->SuspendLayout();
//
// serializationDemoControl
//
this->serializationDemoControl->Location =
System::Drawing::Point(0, 0);
this->serializationDemoControl->Name =
"serializationDemoControl";
this->serializationDemoControl->Padding =
System::Windows::Forms::Padding(5);
this->serializationDemoControl->TabIndex = 0;
//
// SerializationDemoForm
//
this->AutoScaleBaseSize = System::Drawing::Size(5, 13);
this->ClientSize = System::Drawing::Size(292, 273);
this->Controls->Add(this->serializationDemoControl);
this->Name = "SerializationDemoForm";
this->Text = "Form1";
this->ResumeLayout(false);
}
};
};
[STAThread]
int main()
{
Application::EnableVisualStyles();
Application::Run(gcnew SerializationDemo::SerializationDemoForm());
}
------ 已启动生成: 项目: 7, 配置: Debug Win32 ------
正在编译...
7.cpp
c:\documents and settings\administrator\桌面\c\7\7\7.cpp(1) : fatal error C1190: 托管目标代码需要“/clr”选项
生成日志保存在“file://c:\Documents and Settings\Administrator\桌面\C\7\7\Debug\BuildLog.htm”
7 - 1 个错误,0 个警告
========== 生成: 成功 0 个,失败 1 个,最新 0 个,跳过 0 个 ==========