3

Estou fazendo um projeto na faculdade e queria fazer um sistema de ajuda no Word, com a imagem das telas e explicar o funcionamento, e dentro do projeto criar uma aba Ajuda e quando clicar nela, abrir o que fiz dentro do Word.

Isso é possível e como fazer estou fazendo em Windows Form Desktop?

ou

como eu faria sistema de ajuda com recurso a ficheiros *.chm. e como eu chamaria dentro do meu form ?

5
  • 2
    Por que não exibe as informações em um form? é muito mais fácil e o usuário não terá a obrigação de ter o Office instalado no computador, o que acha? 16/12/2014 às 17:12
  • Concordo com o @PauloHDSousa em não usar o Word por limitar a ajuda a quem tem Office. Crie o sistema de ajuda com recurso a ficheiros *.chm.
    – jpmnteiro
    16/12/2014 às 17:21
  • Talvez uma ajuda em HTML?
    – Caputo
    16/12/2014 às 17:27
  • 1
    Não sei o que tem pronto pra Windows Forms, mas provavelmente se salvar como RTF é capaz de já poder usar sem converter.
    – Largato
    16/12/2014 às 18:03
  • como eu faria sistema de ajuda com recurso a ficheiros *.chm. e como eu chamaria dentro do meu form ? 16/12/2014 às 23:06

2 Respostas 2

1

Como pode ser visto neste post do blog do David Morton você pode converter para HTML o documento do Word e exibir em um embembed Web Browser.

using System;
using System.Linq;
using System.Windows.Forms;
using Microsoft.Office.Interop.Word;
using System.IO;

namespace WordControls
{
    public partial class DocBrowser : UserControl
    {
        private System.Windows.Forms.WebBrowser webBrowser1;

        delegate void ConvertDocumentDelegate(string fileName);

        public DocBrowser()
        {
            InitializeComponent();

            // Create the webBrowser control on the UserControl. 
            // This code was moved from the designer for cut and paste
            // ease. 
            webBrowser1 = new System.Windows.Forms.WebBrowser();

            webBrowser1.Dock = System.Windows.Forms.DockStyle.Fill;
            webBrowser1.Location = new System.Drawing.Point(0, 0);
            webBrowser1.MinimumSize = new System.Drawing.Size(20, 20);
            webBrowser1.Name = "webBrowser1";
            webBrowser1.Size = new System.Drawing.Size(532, 514);
            webBrowser1.TabIndex = 0;

            Controls.Add(webBrowser1);

            // set up an event handler to delete our temp file when we're done with it. 
            webBrowser1.DocumentCompleted += webBrowser1_DocumentCompleted;
        }

        string tempFileName = null;

        public void LoadDocument(string fileName)
        {
            // Call ConvertDocument asynchronously. 
            ConvertDocumentDelegate del = new ConvertDocumentDelegate(ConvertDocument);

            // Call DocumentConversionComplete when the method has completed. 
            del.BeginInvoke(fileName, DocumentConversionComplete, null);
        }

        void ConvertDocument(string fileName)
        {
            object m = System.Reflection.Missing.Value;
            object oldFileName = (object)fileName;
            object readOnly = (object)false;
            ApplicationClass ac = null;

            try
            {
                // First, create a new Microsoft.Office.Interop.Word.ApplicationClass.
                ac = new ApplicationClass();

                // Now we open the document.
                Document doc = ac.Documents.Open(ref oldFileName, ref m, ref readOnly,
                    ref m, ref m, ref m, ref m, ref m, ref m, ref m,
                     ref m, ref m, ref m, ref m, ref m, ref m);

                // Create a temp file to save the HTML file to. 
                tempFileName = GetTempFile("html");

                // Cast these items to object.  The methods we're calling 
                // only take object types in their method parameters. 
                object newFileName = (object)tempFileName;

                // We will be saving this file as HTML format. 
                object fileType = (object)WdSaveFormat.wdFormatHTML;

                // Save the file. 
                doc.SaveAs(ref newFileName, ref fileType,
                    ref m, ref m, ref m, ref m, ref m, ref m, ref m,
                    ref m, ref m, ref m, ref m, ref m, ref m, ref m);

            }
            finally
            {
                // Make sure we close the application class. 
                if (ac != null)
                    ac.Quit(ref readOnly, ref m, ref m);
            }
        }

        void DocumentConversionComplete(IAsyncResult result)
        {
            // navigate to our temp file. 
            webBrowser1.Navigate(tempFileName);
        }

        void webBrowser1_DocumentCompleted(object sender,
            WebBrowserDocumentCompletedEventArgs e)
        {
            if (tempFileName != string.Empty)
            {
                // delete the temp file we created. 
                File.Delete(tempFileName);

                // set the tempFileName to an empty string. 
                tempFileName = string.Empty;
            }
        }

        string GetTempFile(string extension)
        {
            // Uses the Combine, GetTempPath, ChangeExtension, 
            // and GetRandomFile methods of Path to 
            // create a temp file of the extension we're looking for. 
            return Path.Combine(Path.GetTempPath(),
                Path.ChangeExtension(Path.GetRandomFileName(), extension));
        }
    }
}

PS.: Uma outra opção seria utilizar o OleAutomation do world e abrir a aplicação dentro do seu aplicativo. Exemplos desse tipo podem ser visto neste outro post

1

Você poderia utilizar o SandCastle para criar arquivos .chm e utilizar o recurso de System.Windows.Forms.Help.ShowHelp para abrir este arquivo CHM;

Veja um exemplo nesta pergunta do StackOverflow em inglês:

https://stackoverflow.com/questions/6094053/open-chm-help-file-in-c-sharp

Você deve fazer log-in para responder a esta pergunta.

Esta não é a resposta que você está procurando? Pesquise outras perguntas com a tag .