无法在C+;中转换TextBox_TextChanged()+;到C# 我用JUCE库工作C++几个月了。我在我的项目中编写了一段代码,其中textbox的格式仅修改为十六进制值,几乎没有什么功能:

无法在C+;中转换TextBox_TextChanged()+;到C# 我用JUCE库工作C++几个月了。我在我的项目中编写了一段代码,其中textbox的格式仅修改为十六进制值,几乎没有什么功能:,c#,c++,wpf,textbox,C#,C++,Wpf,Textbox,演示: void CMSP430CommPanel::textEditorTextChanged (TextEditor& editor) { if(&editor == m_texti2cWrite) { int count = 0; int location; String text1 = m_texti2cWrite->getText(); String text = m_texti2cWrite->getText().removeCharac

演示:

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);
    }
}
}
12 ab 32 A564

现在,如果我的光标在末尾,我继续按backspace,它应该像在常规文本框中一样删除这些值

现在,如果我的光标位于a5的开头,并且我按下“delete键”,则该值应如下所示:

12 ab 32 56 4

如果我的光标位于a5的末尾,并且我按下“删除键”,则不应发生任何事情。在输入值时,空格键不应让两个值之间的间距为bw。只允许输入a-f和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);
    }
}
}
void CMSP430CommPanel::textEditorExtChanged(TextEditor&editor)
{
if(&editor==m_texti2cWrite)
{       
整数计数=0;
int定位;
字符串text1=m_texti2cWrite->getText();
String text=m_texti2cWrite->getText().removeCharacters(“”);
字符串hexString=String::empty;
int countCaret=m_texti2cWrite->getCaretPosition();
对于(int i=0;isetText(十六进制字符串,false);
如果(text1.length()==m_texti2cWrite->getCaretPosition())
{
m_texti2cWrite->setCaretPosition(计数);
}
其他的
{
m_texti2cWrite->setCaretPosition(countCaret);
}
}
}
我希望在我的WPF应用程序中也能实现同样的功能,比如说在C#中实现同样的代码

请提供帮助!!!

公共类CMSP430CommPanel
public class CMSP430CommPanel
{
    //C++ TO C# CONVERTER WARNING: The original C++ declaration of the following method implementation was not found:
    public void 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);
    }
}
}
}
{ //C++到C·C转换器警告:未找到以下方法实现的原始C++声明: 公共无效textEditorTextChanged(TextEditor) { 如果(编辑器==m_texti2cWrite) { 整数计数=0; int定位; string text1=m_texti2cWrite.getText(); string text=m_texti2cWrite.getText().removeCharacters(“”); 字符串hexString=string.empty; int countCaret=m_texti2cWrite.getCaretPosition(); for(int i=0;i
公共类CMSP430通信面板
{
//C++到C·C转换器警告:未找到以下方法实现的原始C++声明:
公共无效textEditorTextChanged(TextEditor)
{
如果(编辑器==m_texti2cWrite)
{
整数计数=0;
int定位;
string text1=m_texti2cWrite.getText();
string text=m_texti2cWrite.getText().removeCharacters(“”);
字符串hexString=string.empty;
int countCaret=m_texti2cWrite.getCaretPosition();
for(int i=0;i
试试这个(文本框的文本更改事件):

  • 将TextBox\u PreviewTimePut-Event添加到文本框中

    private void TextBox_PreviewTextInput(object sender, TextCompositionEventArgs e)
    {
        e.Handled = !IsTextAllowed(e.Text);
    }
    
  • 尝试以下操作(文本框的文本更改事件):

  • 将TextBox\u PreviewTimePut-Event添加到文本框中

    private void TextBox_PreviewTextInput(object sender, TextCompositionEventArgs e)
    {
        e.Handled = !IsTextAllowed(e.Text);
    }
    

  • 你能把你迄今为止写的C#发布出来吗?我们可以试着帮你(而不是试着为你写完整的东西)?这个解决方案有什么用:?这不管用吗?不,我不知道该怎么做。我从过去几周开始就喜欢这种C#语言:(我以前从未做过这方面的工作:(@FlorianGl:我想要一个简单的方法。我试图实现相同的代码,但没有成功。所以我只想用一个通用的方法,而不是基于MVVM:)你能发布你写的C#到目前为止,我们可以试着帮你(而不是试图为你写完整的东西)吗?这个解决方案有什么用:?这不管用吗?不,我不知道该怎么办。我从过去几周开始就喜欢这种C语言:(我以前从未使用过:(@FlorianGl:我想要一种简单的方法。我试图实现给定的相同代码,但没有成功。所以我只想采用一种通用的方法,而不是基于MVVM的:)根据我的说法,C语言中没有getcaretposition()、gettext()等,尽管有很多方法可以实现etc在C#中可用,但我认为有很多方法。使用您的上述代码。以下问题:1.它接受所有内容,即只接受0-9和a-f。2.输入2个数字后,当我尝试输入第3个数字时,光标会转到第一个位置,并以相反的方式添加。尽管它应该删除数字工作正常:)但每次光标移动到第一个位置好的,我写了一个代码,将oly限制为0-9和a-f。现在第2个问题如何?:)第2个问题应该已经解决了,如果(text1.Length==countCaret){m_texti2cWrite.Select(count,0);