简体   繁体   中英

How can I position elements using relative percentages in winform

I have this card table form with one main player and four opponents:

在此处输入图片说明

Opponent 2 and Opponent 3 are anchored to the top, as is everything in the middle. Main Player, Opponent 1, and Opponent 4 are anchored to the bottom. But when I maximize the window, since the background image gets stretched, the bottom players end up getting placed outside the table like so:

在此处输入图片说明

My question is, how do I position the bottom players in terms of percentages of the form dimensions so they stay inside the table? Or is there any way of anchoring them that will serve my purpose? Any and all help is appreciated.

Anchoring should be enough.

You could:
Anchor (2): Top-Left, Middle Top: Top, (3): Top-Right
Anchor (1): Left, Middle Bottom: Bottom, (4): Right

Plus, at design time, resize your container (a form maybe) to the minimum size below which your layout looses meaning and set that dimension as the hard-coded MinimunSize of the container.

Anchoring to a single dimension is proportional. Anchor Left can be expressed as:

RefRatio = (OriginalViewPort.Height - RefControl.Height) * 2
RefTop = RefControl.Top
RefLeft = RefControl.Left
OnResize => RefControl.Top = RefControl.Top - (int)(RefControl.Top - RefTop) / RefRatio)
            RefControl.Left = RefLeft

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM