2013-04-04 20 views
1

我想给用户选择更改字体大小,同时在Richeditbox中输入文本。 我有下面的代码:如果我使用的输入设备如鼠标和键盘时正常工作RichEditBox字体大小C#窗口存储应用程序无响应

void textBox_GotFocus(object sender, RoutedEventArgs e) 
    { 
      RichEditBox textBox = sender as RichEditBox; 

      ITextSelection selectedText = currentTextBox.Document.Selection; 
      if (selectedText != null) 
      { 
       ITextCharacterFormat charFormatting = selectedText.CharacterFormat; 
       charFormatting.Size = (float)textBoxFontSize; 
       selectedText.CharacterFormat = charFormatting; 
      }     
    } 

此代码调用。 如果我使用触摸屏并在上述函数内部放置调试点,此代码也可以使用。

但是,如果我使用触摸屏作为输入设备,并且代码中没有断点,则字体大小会自动变为10.5,并且永远不会变回。

我看到正在面临其他类似的问题:

http://social.msdn.microsoft.com/Forums/en-US/winappswithcsharp/thread/771b6374-37da-4cdd-b68c-7b50b939b775

+0

你尝试过这样的事情 'editor.Document.GetRange(0,int.MaxValue).CharacterFormat.Size = aNewFontSize ;' – MethodMan 2013-04-04 20:39:25

+0

Hi @DJKRAZE, 添加了这段代码: 'string currentTextBoxText = null; textBox.Document.GetText(TextGetOptions.None,out currentTextBoxText); int textLength = currentTextBoxText.Length - 1; currentTextBox.Document.GetRange(textLength,int.MaxValue).CharacterFormat.Size =(float)textBoxFontSize;' 它正在工作。 非常感谢。 – 2013-04-04 21:37:53

回答

0

感谢DJ KRAZE 问题得到彻底解决。 这里是一个响应鼠标键盘和触控交互以及解决方案:

string currentTextBoxText = null; 
textBox.Document.GetText(TextGetOptions.None, out currentTextBoxText); 
int textLength = currentTextBoxText.Length - 1; 
currentTextBox.Document.GetRange(textLength, int.MaxValue).CharacterFormat.Size = (float)textBoxFontSize;