Frage

I am able to create a document and window using the mshtml library in C#. But when I do this the window appears to have a height and width of 0.

I can use window.open("about:blank", null, "height=1000,width=1000") but then it actually pops open a new window and what I want should be all in code.

My question is, how can I create that original window to be of a certain size? window.resizeTo(1000, 1000) has no effect at all.

var document = (IHTMLDocument2)new HTMLDocument();
var window = document.parentWindow;
window.resizeTo(1024, 768); // has no effect

document.write(new object[] { html });
document.close();
window.execScript(script, "javascript"); // error in my script due to window size
War es hilfreich?

Lösung

The trick is to just use a WebBrowser control found in either WinForms (System.Windows.Forms) or WPF (System.Windows.Controls) instead. Then you can put it into a proper Window, Show() it then all of the sizing and layout happens as expected.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top