![](/img/trans.png)
[英]How to display a Modal form in a position relative to the a control in the parent window (opener)
[英]How to position objects relative to their parent
我想知道是否有可能相對於其父面板定位面板。 例如,我有一個小組,通常每隔一個小組會收到一個子小組,但沒有這樣做:
newChildPanel.Location = Point.Add(parentPanel.Location,desiredLocation);
我想說:
newChildPanel.Location = Size.new(0,64);
有什么辦法嗎?
newChildPanel.Location =新Point(0,64);
您可以通過定義新點來設置位置: newChildPanel.Location = new Point(0, 64)
。 這將相對於父母的位置。
例如:
Panel parent = new Panel();
parent.BackColor = Color.Red;
parent.Location = new Point(20, 25);
Controls.Add(parent);
Panel child = new Panel();
child.Parent = parent;
child.BackColor = Color.Blue;
child.Location = new Point(5, 5);
給出以下結果:
如您所見,子面板(藍色)相對於父面板(紅色)的位置被添加在(5,5)處。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.