如何在桌面应用程序的富文本框中打开带有图像和项目符号的Word文件.

问题描述:

您好,我可以打开一个没有格式的Word文件,只在富文本框中包含文本.文件已正确打开,但现在我想打开包含图像和项目符号的Word文件.

如何打开它?

感谢Advance-

Hi, I am able open a word file which has no format and only contain text in a rich text box.file is open properly but now i want to open a word file with images and bullets .

how to open this ?

Thanks in Advance-

如果将Word文档保存到RTF文件,则可以使用LoadFile方法将其打开.
但是,使用RichTextBox可能会遇到很多问题.考虑使用例如 http://www.freetextbox.com/ [
If you save the word document to a RTF file, you can open it using LoadFile method.

However using a RichTextBox can be quite problematic. Consider using for example http://www.freetextbox.com/[^] and HTML format for the Word contents


System.Windows.Forms.RichTextBox中,图像不受很好的支持.无论如何,有一种方法可以使用剪贴板插入它们.

例如:
In System.Windows.Forms.RichTextBox, images are not well supported. Anyway, there is a way to insert them using the clipboard.

For example:
Image img = Image.FromFile("myImage.jpg");
Clipboard.SetImage(img);
myRichTextBox.SelectionStart = 0; //for example; you need some position to insert it
myRichTextBox.SelectionLength = 0;
myRichTextBox.Paste();

但是,您可能会面对太多的问题.

我建议您使用其他替代方法.可以使用HTML代替RTF格式.我会推荐此CodeProject文章中提供的精彩组件:

您将使用的专业HTML渲染器 [ ^ ].

—SA

However, you can face too many problems with that.

I would advice you to use some alternative. Instead of Rich Text Format, you could use HTML. I would recommend this wonderful component offered in this CodeProject article:

A Professional HTML Renderer You Will Use[^].

—SA


我正在使用此代码打开单词文件-
i am using this code to open a word file-
Microsoft.Office.Interop.Word.ApplicationClass wordObject = new Microsoft.Office.Interop.Word.ApplicationClass();
                object File = txtfilepath.Text; //this is the path
                object nullobject = System.Reflection.Missing.Value;
                Microsoft.Office.Interop.Word.Application wordobject = new Microsoft.Office.Interop.Word.Application();
                wordobject.DisplayAlerts = Microsoft.Office.Interop.Word.WdAlertLevel.wdAlertsNone;
                Microsoft.Office.Interop.Word._Document docs = wordObject.Documents.Open(ref File, ref nullobject, ref nullobject, ref nullobject,
                ref nullobject, ref nullobject, ref nullobject, ref nullobject,
                ref nullobject, ref nullobject, ref nullobject, ref nullobject,
                ref nullobject, ref nullobject, ref nullobject, ref nullobject);
                docs.ActiveWindow.Selection.WholeStory();
                docs.ActiveWindow.Selection.Copy();
                
                IDataObject data = Clipboard.GetDataObject();
                rtbgermanfile.Text = data.GetData(DataFormats.Rtf).ToString();
                string name = rtbgermanfile.Text.Trim();
                name = String.Join(Environment.NewLine, name.Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries));
                string newtext = name.Replace("\n\n", "\n");
                string newtext2 = newtext.Replace("\n\n", "\n");
                rtbgermanfile.Text = newtext2.ToString();
                txtwriteingerman.Text = rtbgermanfile.Lines[0];
                docs.Close(ref nullobject, ref nullobject, ref nullobject);
                wordobject.Quit(ref nullobject, ref nullobject, ref nullobject);
                //wordobject.Quit(SaveChanges:false, OriginalFormat: false, RouteDocument: false);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(wordobject);
                txtwriteinenglish.Focus();


但它只打开文本.
我想对图片和项目符号发表意见.


but it open only text .
i want to opne image and bullets.