Calculation of the internal container size of the Flex panel control

Source: Internet
Author: User

Key words: Flex, panel, viewmetrics

In Flex, the panel control is a special container control. This control looks like a window because it has a title bar and a border. The actual use area is the internal white area. The width attribute and

The height attribute includes borders. Sometimes we need to know the internal container size accurately. There is no good way, only 1.1 points to try, try out the border size, it is very troublesome, and when the panel control

After the style is changed, the Border width may change. Is there any way to accurately know the size of the border.
Fortunately, we accidentally discovered a viewmetrics attribute of the panel control, which is an edgemetrics object, which has four attributes: Left, right, top, and bottom, the four attributes Save the upper and lower left

The value of the right border. Based on these four values, you can easily obtain the size of the valid part in the panel container.
Here is a small example:
<? XML version = "1.0" encoding = "UTF-8"?> <Br/> <mx: Application xmlns: MX = "http://www.adobe.com/2006/mxml" layout = "absolute"> <br/> <mx: SCRIPT> <br/> <! -- [CDATA [<br/> Import MX. events. flexevent; <br/> Import MX. controls. image; <br/> private var IMG: image; <br/> private function onclick (): void <br/>{< br/> IMG = new image (); <br/> IMG. source = "image. PNG "; <br/> panel. addchild (IMG); <br/>}< br/> private function onclick2 (): void <br/>{< br/> panel. width = IMG. width + panel. viewmetrics. left + panel. viewmetrics. right; <br/> panel. height = IMG. height + panel. viewmetrics. top + panel. viewmetrics. bottom; <br/>}< br/>] --> <br/> </MX: SCRIPT> <br/> <mx: panel id = "Panel" x = "133" Y = "98" width = "398" Height = "360" layout = "absolute"> <br/> </MX: panel> <br/> <mx: button x = "133" Y = "52" label = "showpicture" Click = "onclick () "/> <br/> <mx: button x =" 362 "Y =" 52 "label =" resizepanel "Click =" onclick2 () "/> <br/> </MX: Application>

In this example, press the showpicture button to add an image to the Panel. If the Panel size is not changed, the scroll bar appears and the image is incomplete. 1:

Figure 1


Next, press the resizepanel button to adjust the Panel size. In this example, the viewmetrics attribute is used to dynamically adjust the Panel size.
In this way, the entire image is displayed completely. 2:

Figure 2

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.