如题.开发一个类似WORD的程序.要保存图片到RichTextBox 

解决方案 »

  1.   

    private bool pasteMyBitmap(string fileName)
    { // Open an bitmap from file and copy it to the clipboard.
    Bitmap myBitmap = new Bitmap(fileName);

    // Copy the bitmap to the clipboard.
    Clipboard.SetDataObject(myBitmap); // Get the format for the object type.
    DataFormats.Format myFormat = DataFormats.GetFormat(DataFormats.Bitmap); // After verifying that the data can be pasted, paste it.
    if(richTextBox1.CanPaste(myFormat))
    {
    richTextBox1.Paste(myFormat);
    return true;
    }
    else
    {
    MessageBox.Show("The data format that you attempted to paste is not supported by this control.");
    return false;
    }
    }
      

  2.   


    //仅供参考
    using MSWord = Microsoft.Office.Interop.Word;
    using System.IO;
    using System.Reflection;class Program
    {
      static void Main(string[] args)
      {
        string wPath = @"d:\Myword.docx";
        MSWord.Application wordApp = new MSWord.ApplicationClass();
        Object nothing = Missing.Value;
        MSWord.Document wordDoc = 
              wordApp.Documents.Add(ref nothing,ref nothing,ref nothing,ref nothing)
        string fileName = @"d:\myImage.jpg";
        Object range = wordDoc.Paragraphs.Last.Range;
        Object linkToFile = false;
        Object saveWithDoc = true;
        wordDoc.InlineShapes.AddPicture(fileName,ref linkToFile,ref saveWithDoc,ref range);
        Object format = MSWord.WdSaveFormat.wdFormatDocumentDefault; //2007版
         wordDoc.SaveAs(ref wPath,ref format,ref nothing,ref nothing,ref nothing,ref nothing,
              ref nothing,ref nothing,ref nothing,ref nothing,ref nothing,
              ref nothing,ref nothing,ref nothing,ref nothing,ref nothing)
        wordDoc.Close(ref nothing,ref nothing,ref nothing);
        wordDoc.Quit(ref nothing,ref nothing,ref nothing);
      }
    }
      

  3.   

    private bool pasteMyBitmap(string fileName)
            {
                Bitmap myBitmap = new Bitmap(fileName);
                Clipboard.SetDataObject(myBitmap);
                DataFormats.Format myFormat = DataFormats.GetFormat(DataFormats.Bitmap);
                if (news_body.CanPaste(myFormat))
                {
                    news_body.Paste(myFormat);
                    return true;
                }
                else
                {
                    MessageBox.Show("呵呵");
                    return false;
                }
            }