2014-11-24 2 views
2

White's UI automation framework을 사용하여 RichTextBox에서 텍스트를 읽으려고하지만 항상 null을 반환합니다. RichTextBox에 대한 자동화 지원 - White'sUI를 사용하여 텍스트를 가져올 수 없습니다.

는 이미 RichtextBox.cs
protected override AutomationPeer OnCreateAutomationPeer() 
    { 
     return new RichTextBoxAutomationPeer(this); 
    } 

텍스트를 얻을 수있는 해결 방법이

에 아래 코드를 추가? 또는 TextPattern을 사용하여?

답변

1

저는 지금은 한동안 흰색을 사용하고 있습니다. 실제로는 늦었지만 같은 문제가있었습니다. 나는 텍스트 패턴을 사용하여 서식있는 텍스트 상자에서 값을 가져오고, 아래의 샘플 코드를 찾고, 어쨌든 도움이되기를 바랍니다.

AutomationElement ele =window.GetElement(SearchCriteria.ByAutomationId("richTextBoxId>")); 

     if (ele != null) 
     { 
      TextPattern txtPattern = ele.GetCurrentPattern(TextPattern.Pattern) as TextPattern; 
      String controlText = txtPattern.DocumentRange.GetText(-1); 
      Debug.WriteLine("the text is" + controlText); 

     } 
관련 문제