2013-04-04 17 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;