Reputation: 14787
I am trying to control the window location of Word.
My WinForms (C#) application takes up the bottom half of the screen and launches an instance of Word. I need this instance to take the upper half of the screen.
This cannot be controlled through interop so I managed to to get the Window Handle of the Word instance. Then I tried using SetWindowPos, SetWindowsLong, etc. in various ways but without any visible results.
Instead of posting buggy code all over again, I wanted a fresh start so any suggestions are welcome from people who have achieved something like this.
Upvotes: 2
Views: 604
Reputation: 10347
You can use Application.Move method. or set Application.Top or Application.Left properties directly. your code can be like this:
private Word.Application WordApp = new Word.Application();
...
private void buttonClick(object sender, System.EventArgs e)
{
if (this.openFileDialog.ShowDialog() == DialogResult.OK)
{
object fileName = openFileDialog.FileName;
object visible = true;
object missing = System.Reflection.Missing.Value;
WordApp.Visible = true;
Word.Document aDoc =
WordApp.Documents.Open(ref fileName, ref missing, ref missing,
ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing,
ref missing, ref missing, ref visible);
aDoc.Activate();
WordApp.Top = 0;
}
}
dont forget to add Microsoft Word Object Library to your references and using related namespace:
using Microsoft.Office.Interop.Word;
Upvotes: 2