[英]RichTextBox.RTF not accepting String generated from Database - C#
[英]C# richtextbox show image from RTF
为什么我的richtextbox只显示RTF代码而不显示图像? 这是rtf代码:
{\\ pict \\ pngblip \\ picw800 \\ pich600 \\ picwgoal6400 \\ pichgoal4800 \\ hex}
实际上它很长,只是删了一些。
但如果格式以 - > {rtf ........开头,它显示了图像
提前致谢
假设WinForms RichTextBox,那么是的,RichTextBox的内容必须是一个有效的RTF文档,因此它需要以{\\rtf1
元素开头并以结束括号结束}
。
例:
{\\ rtf1 {\\ pict \\ pngblip \\ picw800 \\ pich600 ...... blah blah blah ..... 44AE426082}}
如果你的rtf glob只是一个字符串变量,那么你可以这样做:
richTextBox1.Rtf = @"{\rtf1" + picText + "}";
要在富文本框中显示内嵌图像,您必须执行以下操作:
//A RichTextBox with an image.
private void ImageRTB()
{
//Create a new RichTextBox.
RichTextBox MyRTB = new RichTextBox();
// Create a Run of plain text and image.
Run myRun = new Run();
myRun.Text = "Displaying text with inline image";
Image MyImage = new Image();
MyImage.Source = new BitmapImage(new Uri("flower.jpg",
UriKind.RelativeOrAbsolute));
MyImage.Height = 50;
MyImage.Width = 50;
InlineUIContainer MyUI = new InlineUIContainer();
MyUI.Child = MyImage;
// Create a paragraph and add the paragraph to the RichTextBox.
Paragraph myParagraph = new Paragraph();
MyRTB.Blocks.Add(myParagraph);
// Add the Run and image to it.
myParagraph.Inlines.Add(myRun);
myParagraph.Inlines.Add(MyUI);
//Add the RichTextBox to the StackPanel.
MySP.Children.Add(MyRTB);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.