客户端区域更改时,将Align设置为alClient的TWebBrowser不会调整大小 [英] TWebBrowser with Align set to alClient will not resize when client area changes

查看:109
本文介绍了客户端区域更改时,将Align设置为alClient的TWebBrowser不会调整大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有多个拆分器和面板的表单.中间是一个面板,该面板最后设置了TWebBrowser以对齐alClient.

I have a form with several splitters and panels. In the middle is a panel that ends up with a TWebBrowser set to align alClient.

过去,这种方法效果很好.但是,在带有Internet Explorer 8的Windows 7上,无法正确调整浏览器的大小.其他所有内容(即面板)的尺寸都是正确的,而不是Web浏览器的尺寸.有时,当您单击浏览器时,或更经常地,当您滚动浏览器时,将跳到正确的大小.但是,那并不是100%的时间发生.

In the past this has worked well. However, on Windows 7 with Internet Explorer 8 the the browser is not correctly resized. Everything else (i.e. the panels) are the correct size, just not the web browser. Sometimes when you click into the browser, or more often when you scroll the browser will jump to the correct size. That does not happen 100% of the time though.

我正在尝试直接处理调整大小并强制控件更改大小.我似乎找不到找到任何方法的方法(即.Invalidate; .Repaint; .Update;)

I'm trying to deal with the resize directly and force the control to change size. I can't seem to find a method that makes any difference (i.e. .Invalidate; .Repaint; .Update;)

TWebBrowser是包装Internet Explorer控件的OLE控件(ActiveX).关于如何进行尺寸调整的任何想法?

TWebBrowser is an OLE control (ActiveX) that wraps the Internet Explorer control. Any ideas on how I can make the resize happen?

更新背景

我将其范围缩小到仅当我有一个子窗体时才发生,而我将其父窗体放置在另一个窗体中.我的TWebBrowser控件位于我需要显示HTML文档时使用的子窗体上.

I narrowed this down to only happening when I have a child form that I change the parent to site it inside another form. My TWebBrowser control is on a child form that I use anytime I need to show an HTML document.

在我的父表单中,我有一个网格,一个拆分器和一个面板,该面板的网格设置为顶部对齐",该面板设置为对齐客户端".我的子窗体(称为THtmlViewer)将其父窗体设置为面板. THtmlViewer表单设置为alClient,子表单上的TWebBrowser控件也设置为对齐客户端.

In my parent form I have a Grid, a splitter, and a panel with the grid set to Align top and the panel set to align client. My child form (called THtmlViewer) has its parent set to the panel. The THtmlViewer form is set to alClient and TWebBrowser control on the child form is also set to align client.

如果我以调整THtmlViewer表单大小的形式进行任何操作,都会遇到此问题.直接在FormResize中或间接使用align属性的所有内容.但是,如果我从父表单中调用我的调整大小,则一切正常.

If I do anything in the form resize of the THtmlViewer form I run into this issue. Anything being directly in FormResize or indirectly using the align properties. However, if I call my resize from the parent form everything works fine.

关键似乎是关闭THtmlViewer表单中的调整大小代码.如果我留下一个OnResize处理程序或对齐方式集,那么我在父级中做什么都没有关系,那么调整大小将无法正确进行.

The key seems to be turning off the resize code in the THtmlViewer form. If I leave a OnResize handler or the alignment set then it does not matter what I do in the parent, the resize is not done correctly.

我仍然很困惑为什么需要这样做以及为什么我不能强迫它以正确的调整大小(THtmlViewer)进行更新.

I am still confused why this is needed and why I can't force it to update in the correct resize (THtmlViewer).

作为旁注,我还注意到Windows 7上的Delphi 2007与IDE中的欢迎页面"存在完全相同的问题.

As a side note I also noticed that Delphi 2007 on Windows 7 has the exactly same problem with the "Welcome Page" in the IDE.

我已解决此问题,方法是添加一个方法来将子窗体的OnResize设置为nil,然后从父窗体的OnResize处理程序调用我的内部ForceResize.我仍然想从THtmlViewer表单中处理所有这一切,并接受一个让我避免这种黑客攻击的答案.

I have worked around the issue by adding a method to set OnResize of the child form to nil and then call my internal ForceResize from the parent's OnResize handler. I would still like to deal with this all from the THtmlViewer form and would accept an answer that let's me avoid this hack.

推荐答案

要在控件的容器更改大小时调整控件的大小,除了仅"使用Align属性之外,还有两个选择:

To resize controls when their container changes size, you have two other options besides using "just" the Align property:

  • 使用不带Align属性的Anchors属性,即将Align属性设置为alCustom或alNone,然后根据需要设置锚点.由于Align属性是设置锚点的捷径,因此它依赖于相同的对齐处理,因此在您的情况下可能不起作用.

  • Use the Anchors property without the Align property, that is, set the Align property to alCustom or alNone, then set the anchors according to your needs. As the Align property is sort of short-hand for setting the Anchors, this is dependent upon the same alignment processing so may not work in your case.

为TWebBrowser所在的容器的OnResize事件提供一个处理程序,并手动将TWebBrowser的高度和宽度设置为容器的高度和宽度(可以根据需要在容器内设置的任何边距进行调整). /p>

Provide a handler for the OnResize event of the container on which the TWebBrowser sits and manually set the TWebBrowser's height and width to those of the container (optionally adjusted for any margins you want to have within the container).

也就是说,我没有Windows7,所以我不能保证这样做不会花费更多时间.

That said, I don't have Windows7, so I can't vouch that this won't take more twiddling.

如果您的TWebBrowser在滚动或单击时跳转到正确的大小,则表明控件的大小正确,只是从未收到或处理过消息以实际响应更改.

If your TWebBrowser jumps to the correct size on a scroll or click, it indicates that the control was sized correctly, just never received or processed the messages to actually respond to the changes.

这可能是因为重新对齐控件试图防止不必要的重绘和递归,并且以某种方式混淆了它们.然后,使用OnResize方法可能会获得更好的结果,因为它直接与TWebBrowser对话".

This can be because realigning controls tries to prevent unnecessary repaints and recursions and somehow got mixed up. Using the OnResize method may then get better results as it "speaks to the TWebBrowser directly".

除非控件的ControlStyle中包含csOpaque,否则Repaint是Invalidate和Update的简略"缩写,在这种情况下,绘制看起来更加直接.因此,您可以尝试摆弄TWebBrowser的Transparent属性和/或它所在的容器.

Repaint is "just" shorthand for Invalidate and Update unless the control has csOpaque in its ControlStyle, in which case painting seems more immediate. So you could try to fiddle with the Transparent property of the TWebBrowser and/or the container it sits on.

如果其他所有方法均失败,则可以尝试直接将WM_PAINT(或类似内容)发送到TWebBrowser.例如在TWebBrowser或它所在的容器的OnResize事件中. TWebBrowser的WM_Paint处理程序调用OleDraw,后者直接使用ClientRect与ActiveX进行通信,从OnResize事件调用时,ClientRect的尺寸应正确.

If all else fails, you could try to send a WM_PAINT (or similar) to the TWebBrowser directly. For exmample in the OnResize event of the TWebBrowser or the container it sits on. The a WM_Paint handler of the TWebBrowser calls OleDraw, which talks to the ActiveX directly using the ClientRect, which should have the correct dimensions when called from an OnResize event.

这篇关于客户端区域更改时,将Align设置为alClient的TWebBrowser不会调整大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆