せっかくなんで、私が思いついた方法を書いてみます。(未テスト)
//フォームメンバ
TextBox^ textBox1;
String^ strOldText;
//フォームコンストラクタ
this->textBox1 = gcnew TextBox();
this->textBox1->ModifiedChanged += gcnew EventHandler(this, &Form1::textBox1_ModifiedChanged);
strOldText = "";
//イベントハンドラ
void textBox1_ModifiedChanged(Object^ sender, EventArgs^ e)
{
TextBox^ ctlText = dynamic_cast<TextBox^>(sender);
if(ctlText != nullptr)
{
array<Char>^ aryCheck = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'A', 'B', 'C', 'D', 'E', 'F'};
int nIdx1 = ctlText->Text->Length - 1;
while(nIdx1 >= 0)
{
int nIdx2 = aryCheck->Length - 1;
while(nIdx2 >= 0)
{
if(ctlText->Text[nIdx1] == aryCheck[nIdx2])
{
break;
}
nIdx2--;
}
if(nIdx2 < 0)
{
break;
}
nIdx1--;
}
if(nIdx1 >= 0)
{
ctlText->Text = strOldText;
ctlText->Select(textBox1->Text->Length, 0);
}
else
{
strOldText = ctlText->Text;
}
ctlText->Modified = false;
}
}
お礼
御回答ありがとうございます。 試しましたところ、期待動作をさせることが出来ました。 ありがとうございました。