winform fails to set size correctly!

M

MeteoBFG

There must be something happening behind the scenes to "help" me, but I've
got a real problem.

I've embedded an AxWebBrowser directly onto a form, and I'm trying to set
the size of the form to accomodate the contents. The width sets to a
predefined number of pixels (816) correctly, but I can't get the height to
work. The code setting the height is below.

You can see what I'm doing is trying to set the form to be so tall that
there's no vertical scrollbar. I do that by asking for the size of the
scrollHeight, and growing the form so the client area is as large as the
value of scrollHeight. But this code fails. The value of desiredHeight
comes back with 7409, and the currentHeight is 293, for a delta of 7116 and
a targetHeight of 7436. But when I set "this.Height = 7436" the form only
grows to to 1036. That number is always the same.

My screen resolution is 1280 * 1024. Does that affect the maximum possible
size of a winform? Would I get the growth I need if I rendered this
offscreen? The real reason I'm trying to work this out anyway is to do a
screen capture and turn HTML into TIFFs, so doing it offscreen (or in
memory) is the real target here, anyway.

private void FitVertical()

{

MSHTML.HTMLDocumentClass doc =
(MSHTML.HTMLDocumentClass)AxWebBrowser.Document;

MSHTML.HTMLBodyClass body = (MSHTML.HTMLBodyClass)doc.body;

int desiredHeight = body.scrollHeight;

int currentHeight = this.ClientSize.Height;

int delta = desiredHeight - currentHeight;

int targetHeight = this.Height + delta;

this.Height = targetHeight;

}
 
S

Stoitcho Goutsev \(100\) [C# MVP]

Hi MeteoBFG,

Yes, this size of the form is limited to the size of the desktop (more
specifcally SystemInformation.MaxWindowTrackSize).
This is done in the Form.SetBoundsCore protected virtual method. This
behaviour cannot be changes or at least without a great deal of work and
using PInvoke.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top