私は数ヶ月間、JuceLibraryでC++に取り組んでいました。私は自分のプロジェクトで、テキストボックスのフォーマットがいくつかの機能を備えた16進値のみに変更されたコードを作成しました。
デモンストレーション:
12 ab 32 a5 64
カーソルが最後にあり、バックスペースを押し続けると、一般的なテキストボックスで発生するように、値が削除されます。
ここで、カーソルがa5の先頭にあり、「Deleteキー」を押すと、値は次のようになります。
12 ab 32 56 4
カーソルがa5の終わりにあり、「削除キー」を押しても何も起こりません。値を入力している間、スペースバーは間隔bwに2つの値を許可しないでください。afと0〜9のみを入力できます。
ここでC++のコード:
void CMSP430CommPanel::textEditorTextChanged (TextEditor& editor)
{
if(&editor == m_texti2cWrite)
{
int count = 0;
int location;
String text1 = m_texti2cWrite->getText();
String text = m_texti2cWrite->getText().removeCharacters(" ");
String hexString = String::empty;
int countCaret = m_texti2cWrite->getCaretPosition();
for(int i=0; i < text.length(); i++)
{
hexString = hexString + String (&text[i], 1);
if((i+1) % 2 == 0)
{
if(i != text.length()-1)
{
hexString = hexString + T(" ");
count ++;
}
}
count ++;
}
m_texti2cWrite->setText(hexString,false);
if(text1.length() == m_texti2cWrite->getCaretPosition())
{
m_texti2cWrite->setCaretPosition(count);
}
else
{
m_texti2cWrite->setCaretPosition(countCaret);
}
}
}
WPFアプリケーションでも同じことが機能するようにしたいと思います。C#での同じコードの一般的な実装を考えてみましょう。
助けてください!!!