Background: I am creating application to capture the screen and paste the screenshot in the word document one below other.
Technical Part: When I run the application, a word document opens along with a form having 'Capture' button. The button when clicked captures the screen and an window is opened asking for the caption and then screenshot with the caption is pasted in currently open word doc.
My Question When user clicks Capture button, I want to check whether the document opened previously is still open or not. If document is not open, I will prompt user to open a new blank document.
I searched many forums and internet, but mostly all suggested to get the filename from the currently running processes. Note that my word document is unsaved, so it will have names like 'Document 1' etc. which will be a bad way to check.
I have pasted my code below for reference.
Any inputs will be appreciated. Thanks in advance.
WordProcessing.cs
namespace WordProcessing
{
class MSWord
{
Word.Application wordApp = new Word.Application(); //Creates new Word Instance
public MSWord()
{
wordApp.Visible = true;
Word.Document oDoc = wordApp.Documents.Add(ref useDefaultValue, ref useDefaultValue, ref useDefaultValue, ref useDefaultValue);
}
}
}
Screencapture.cs
namespace Screencapture
{
public partial class form_capture : Form
{
MSWord word = new MSWord();
public void button1_Click(object sender, EventArgs e)
{
/* Here I want to check whether document opened by 'word' object is still open */
ScreenCapture screen = new ScreenCapture();
screen.CaptureScreenToFile("D:/image.png", System.Drawing.Imaging.ImageFormat.Png);
//Form to ask for caption
DataForm textarea = new DataForm();
textarea.ShowDialog();
textarea.Focus();
word.InsertText(DataForm.textarea_text);
word.InsertImage(@"D:\image.png");
}
}
}
PS: Ignore any syntax errors or missing function definitions. I have pasted shorter version for better understanding.