0
我正在創建一個簡單的C#windows應用程序,我想在其他from中訪問我的richtextbox值。我能夠訪問richtextbox,但是當我試圖訪問它的價值,它給了我空。如何以其他形式獲取richtext框值?
任何建議都有幫助。
我正在創建一個簡單的C#windows應用程序,我想在其他from中訪問我的richtextbox值。我能夠訪問richtextbox,但是當我試圖訪問它的價值,它給了我空。如何以其他形式獲取richtext框值?
任何建議都有幫助。
,如果您使用的WinForms RichTextBox的,那麼你可以簡單的做了以下行動
richtextbox2.Text = richtextbox1.Text;
如果你使用WPF的RichTextBox的看看MSDN的例子用於加載和保存自/至流TextRanges。
節省: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;
}
代碼示例您可以發佈其獲取值的代碼? –