#include "TestClass.h"
#pragma once
namespace My164086 {
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
///
/// WARNING: If you change the name of this class, you will need to change the
/// 'Resource File Name' property for the managed resource compiler tool
/// associated with all .resx files this class depends on. Otherwise,
/// the designers will not be able to interact properly with localized
/// resources associated with this form.
/// </summary>
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::Label^ label1;
protected:
private: System::Windows::Forms::TextBox^ textBox1;
private: System::Windows::Forms::Button^ button1;
private: System::Windows::Forms::Button^ button2;
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)
{
this->label1 = (gcnew System::Windows::Forms::Label());
this->textBox1 = (gcnew System::Windows::Forms::TextBox());
this->button1 = (gcnew System::Windows::Forms::Button());
this->button2 = (gcnew System::Windows::Forms::Button());
this->SuspendLayout();
//
// label1
//
this->label1->AutoSize = true;
this->label1->Location = System::Drawing::Point(9, 9);
this->label1->Name = L"label1";
this->label1->Size = System::Drawing::Size(177, 13);
this->label1->TabIndex = 0;
this->label1->Text = L"Поле для ввода тестовой строки:";
//
// textBox1
//
this->textBox1->Location = System::Drawing::Point(12, 26);
this->textBox1->Name = L"textBox1";
this->textBox1->Size = System::Drawing::Size(340, 20);
this->textBox1->TabIndex = 1;
//
// button1
//
this->button1->Enabled = false;
this->button1->Location = System::Drawing::Point(12, 52);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(340, 23);
this->button1->TabIndex = 0;
this->button1->TabStop = false;
this->button1->Text = L"Кнопка включится когда будет введено 10 символов";
this->button1->UseVisualStyleBackColor = true;
//
// button2
//
this->button2->Location = System::Drawing::Point(13, 82);
this->button2->Name = L"button2";
this->button2->Size = System::Drawing::Size(339, 23);
this->button2->TabIndex = 0;
this->button2->TabStop = false;
this->button2->Text = L"Преобразовать к верхнему регистру";
this->button2->UseVisualStyleBackColor = true;
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(364, 124);
this->Controls->Add(this->button2);
this->Controls->Add(this->button1);
this->Controls->Add(this->textBox1);
this->Controls->Add(this->label1);
this->MaximizeBox = false;
this->MaximumSize = System::Drawing::Size(380, 160);
this->MinimizeBox = false;
this->MinimumSize = System::Drawing::Size(380, 160);
this->Name = L"Form1";
this->Text = L"Form1";
this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
// Обработчик события Load
private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) {
// Создаем документ
document=gcnew TestDocument();
button1->Click+=gcnew EventHandler(document,&TestDocument::Button1ClickEventHandler);
button2->Click+=gcnew EventHandler(document,&TestDocument::Button2ClickEventHandler);
// Связываем документ с контролами формы
textBox1->DataBindings->Add(gcnew Binding(L"Text",document,L"Str",false,DataSourceUpdateMode::OnPropertyChanged,String::Empty));
button1->DataBindings->Add(gcnew Binding(L"Enabled",document,L"EnabledButton"));
button1->DataBindings->Add(gcnew Binding(L"Text",document,L"Button1Caption"));
button2->DataBindings->Add(gcnew Binding(L"Text",document,L"Button2Caption"));
// И больше ни о чем не беспокоимся
}
TestDocument^ document;
};
}
#pragma once
using namespace System;
using namespace System::ComponentModel;
namespace My164086
{
ref class TestDocument:INotifyPropertyChanged // Этот интерфейс позволяет посылать события об исменении свойств документа
{
public:
// Конструктор. Ничего необычного
TestDocument()
{
EnabledButton=false;
Str=String::Empty;
Button1Caption=L"Кнопка включится когда будет введено 10 символов";
Button2Caption=L"Преобразование к верхнему регистру";
toUpCase=true;
}
// Обработчики событий от кнопок
void Button1ClickEventHandler(Object^ sender,EventArgs^ e)
{
Str=String::Empty;
}
void Button2ClickEventHandler(Object^ sender,EventArgs^ e)
{
if(toUpCase)
{
Str=Str->ToUpper();
Button2Caption=L"Преобразовать к нижнему регистру";
}
else
{
Str=Str->ToLower();
Button2Caption=L"Преобразовать к верхнему регистру";
}
toUpCase^=true;
}
// Свойство Str
property String^ Str
{
String^ get(){return str;}
void set(String^ val)
{
if(val!=str)
{
// Если свойство изменилось - обработаем его
str=val;
// И пошлем событие
NotifyPropertyChanged(L"Str");
// Включим или выключим кнопку
if(str->Length<10)EnabledButton=false;
else EnabledButton=true;
}
}
}
// Свойство включения кнопки
property bool EnabledButton
{
bool get(){return enabledButton;}
void set(bool val)
{
if(enabledButton!=val)
{
enabledButton=val;
NotifyPropertyChanged(L"EnabledButton");
if(enabledButton)Button1Caption=L"Теперь нажав на кнопку можно очистить поле ввода";
else Button1Caption=L"Снова ждем 10 символов";
}
}
}
// Заголовки кнопок
property String^ Button1Caption
{
String^ get(){return button1Caption;}
void set(String^ val)
{
if(val!=button1Caption)
{
button1Caption=val;
NotifyPropertyChanged(L"Button1Caption");
}
}
}
property String^ Button2Caption
{
String^ get(){return button2Caption;}
void set(String^ val)
{
if(val!=button2Caption)
{
button2Caption=val;
NotifyPropertyChanged(L"Button2Caption");
}
}
}
// Событие
virtual event PropertyChangedEventHandler^ PropertyChanged;
private:
// Этот метод просто генерирует событие
void NotifyPropertyChanged(String^ info)
{
PropertyChanged(this,gcnew PropertyChangedEventArgs(info));
}
// Скрытые члены
String^ str;
bool enabledButton;
String^ button1Caption;
String^ button2Caption;
bool toUpCase;
};
}
#include "stdafx.h"
#include "Form1.h"
using namespace My164086;
[STAThreadAttribute]
int main(array<System::String ^> ^args)
{
// Enabling Windows XP visual effects before any controls are created
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);
// Create the main window and run it
Application::Run(gcnew Form1());
return 0;
}
Если Вы уже зарегистрированы на Портале - войдите в систему, если Вы еще не регистрировались - пройдите простую процедуру регистрации.