TextInputDialog.cpp
#include "StdAfx.h"
#include "TextInputDialog.h"
using namespace Core;
using namespace System;
using namespace System::Diagnostics;
/// [ Constructor ]
TextInputDialog::TextInputDialog( System::String^ title )
{
// コンポーネントを初期化する
InitializeComponent();
this->Text = title; // ダイアログのタイトル
// フォームをマウス ポインタの位置へ移動する
MoveFormToMousePointer();
}
/// [ Destructor ]
TextInputDialog::~TextInputDialog()
{
if( components != nullptr )
{
delete components;
}
}
#pragma region Windows Form Designer generated code
/// <summary>
/// デザイナ サポートに必要なメソッドです。このメソッドの内容を
/// コード エディタで変更しないでください。
/// </summary>
void TextInputDialog::InitializeComponent(void)
{
this->m_okButton = (gcnew System::Windows::Forms::Button());
this->m_cancelButton = (gcnew System::Windows::Forms::Button());
this->m_textBox = (gcnew System::Windows::Forms::TextBox());
this->SuspendLayout();
//
// m_okButton
//
this->m_okButton->DialogResult = System::Windows::Forms::DialogResult::OK;
this->m_okButton->Location = System::Drawing::Point(12, 39);
this->m_okButton->Name = L"m_okButton";
this->m_okButton->Size = System::Drawing::Size(75, 23);
this->m_okButton->TabIndex = 0;
this->m_okButton->Text = L"確定(&D)";
this->m_okButton->UseVisualStyleBackColor = true;
//
// m_cancelButton
//
this->m_cancelButton->DialogResult = System::Windows::Forms::DialogResult::Cancel;
this->m_cancelButton->Location = System::Drawing::Point(99, 39);
this->m_cancelButton->Name = L"m_cancelButton";
this->m_cancelButton->Size = System::Drawing::Size(75, 23);
this->m_cancelButton->TabIndex = 1;
this->m_cancelButton->Text = L"キャンセル";
this->m_cancelButton->UseVisualStyleBackColor = true;
//
// m_textBox
//
this->m_textBox->Location = System::Drawing::Point(12, 12);
this->m_textBox->Name = L"m_textBox";
this->m_textBox->Size = System::Drawing::Size(162, 19);
this->m_textBox->TabIndex = 2;
//
// TextInputDialog
//
this->AcceptButton = this->m_okButton;
this->AutoScaleDimensions = System::Drawing::SizeF(6, 12);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->CancelButton = this->m_cancelButton;
this->ClientSize = System::Drawing::Size(186, 74);
this->Controls->Add(this->m_textBox);
this->Controls->Add(this->m_cancelButton);
this->Controls->Add(this->m_okButton);
this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::FixedDialog;
this->MaximizeBox = false;
this->MinimizeBox = false;
this->Name = L"TextInputDialog";
this->ShowIcon = false;
this->ShowInTaskbar = false;
this->StartPosition = System::Windows::Forms::FormStartPosition::Manual;
this->Text = L"テキスト入力";
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
/// フォームが最初に表示された
void TextInputDialog::OnShown( System::EventArgs^ e )
{
// 基本クラスの同一関数を呼び出す
System::Windows::Forms::Form::OnShown( e );
// テキストボックスにフォーカスを設定する
Trace::Assert( m_textBox->Focus(), "入力フォーカスが設定される" );
// ... テキストボックスを選択状態にする
m_textBox->SelectAll();
}
/// フォームをマウス ポインタの位置へ移動する
void TextInputDialog::MoveFormToMousePointer()
{
Drawing::Point point = Control::MousePosition; // マウスの位置
// フォームの中心へオフセットする
point.Offset( -this->Size.Width / 2, -this->Size.Height / 2 );
this->Location = point; // フォームの位置
}
/// 空のテキストを禁止する
void TextInputDialog::ProhibitEmptyText()
{
Debug::Assert( m_textBox->Text == String::Empty, "まだテキストは設定されていない" );
// テキストボックスに 内容変更のイベントを追加する
m_textBox->TextChanged += gcnew System::EventHandler( this, &TextInputDialog::TextBoxTextChanged );
// OKボタンを無効にする
m_okButton->Enabled = false;
}
/// テキストボックスの内容が変更された
System::Void TextInputDialog::TextBoxTextChanged( System::Object^, System::EventArgs^ )
{
// 何も入力されていないならば、OKボタンを無効にする
m_okButton->Enabled = ( m_textBox->Text != String::Empty );
}