2011-12-07 8 views
0

私はシンプルなC#のWindowsアプリケーションを作成しています。私はrichtextboxの値に他のものからアクセスしたいと思います。私はrichtextboxにアクセスすることができますが、私はnullの値をアクセスしようとしています。richtext boxの値を他の形式で取得する方法は?

提案が役に立ちます。

+0

からのコード例では、値をフェッチコードを投稿することができますか? –

答えて

0

あなたはリサイズを使用する場合は、WPFのロードについては、MSDNの例を見て、リッチテキストボックスとストリームへの/からTextRangesを保存使用している場合、リッチテキストボックス、あなたは簡単な次のアクション

richtextbox2.Text = richtextbox1.Text; 

を行うことができます。 http://msdn.microsoft.com/en-us/library/ms598701.aspx

ロード:保存

ここhttp://msdn.microsoft.com/en-us/library/system.windows.documents.textrange.load.aspx

は、MSDN

// This method accepts an input stream and a corresponding data format. The method 
// will attempt to load the input stream into a TextRange selection, apply Bold formatting 
// to the selection, save the reformatted selection to an alternat stream, and return 
// the reformatted stream. 
Stream BoldFormatStream(Stream inputStream, string dataFormat) 
{ 
    // A text container to read the stream into. 
    FlowDocument workDoc = new FlowDocument(); 
    TextRange selection = new TextRange(workDoc.ContentStart, workDoc.ContentEnd); 
    Stream outputStream = new MemoryStream(); 

    try 
    { 
     // Check for a valid data format, and then attempt to load the input stream 
     // into the current selection. Note that CanLoad ONLY checks whether dataFormat 
     // is a currently supported data format for loading a TextRange. It does not 
     // verify that the stream actually contains the specified format. An exception 
     // may be raised when there is a mismatch between the specified data format and 
     // the data in the stream. 
     if (selection.CanLoad(dataFormat)) 
      selection.Load(inputStream, dataFormat); 
    } 
    catch (Exception e) { return outputStream; /* Load failure; return a null stream. */ } 

    // Apply Bold formatting to the selection, if it is not empty. 
    if (!selection.IsEmpty) 
     selection.ApplyPropertyValue(TextElement.FontWeightProperty, FontWeights.Bold); 

    // Save the formatted selection to a stream, and return the stream. 
    if (selection.CanSave(dataFormat)) 
     selection.Save(outputStream, dataFormat); 

    return outputStream; 
} 
関連する問題