本文整理汇总了C#中IControl.SetParent方法的典型用法代码示例。如果您正苦于以下问题:C# IControl.SetParent方法的具体用法?C# IControl.SetParent怎么用?C# IControl.SetParent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IControl
的用法示例。
在下文中一共展示了IControl.SetParent方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddControl
public virtual bool AddControl(IControl control)
{
System.Diagnostics.Debug.Assert(control != null, "Can not add a null control");
// Adding a control to itself or to a child of itself
// will unravel the very fabric of the universe
for (IControl parent = this; parent != null; parent = parent.Parent) {
if (parent == control)
throw new InvalidOperationException("Can not add a Control to itself, or to any children of itself.");
}
//_layoutAndAlignChild(control);
if (!_lockControlList()) {
control.Close();
Console.Error.WriteLine("Could not acquire control lock, control discarded.");
return false;
}
try {
_controls.Add(control);
} finally {
_unlockControlList(true);
}
control.SetParent(this);
control.OnResized += this._handleResizeEvent;
control.OnClosed += this._handleClosedEvent;
_layoutAndAlignChildren();
return true;
}
示例2: RemoveControl
public virtual bool RemoveControl(IControl control)
{
if (control.Parent != this) {
Console.Error.WriteLine("Tried to remove control [{0}] that is not a child of parent [{1}].", control.GetType().Name, this.GetType().Name);
return false;
}
if (!_lockControlList())
throw new SynchronizationLockException("Could not acquire control lock, control not removed.");
try {
_controls.Remove(control);
} finally {
_unlockControlList(true);
}
control.SetParent(null);
control.OnResized -= this._handleResizeEvent;
control.OnClosed -= this._handleClosedEvent;
return true;
}