namespace TACO.Widgets { using System; using System.Drawing; using System.Drawing.Drawing2D; public class CanvasSelection : CanvasElement { private CanvasElement mTarget = null; public CanvasSelection(CanvasElement target) : base("##selection") { Target = target; } public override string Name { get { return "Selection"; } } public CanvasElement Target { get { return mTarget; } set { if (mTarget == value) return; if (value == null) { mTarget.VisibilityChanged -= OnElementVisibilityChanged; mTarget.BoundsChanged -= OnElementBoundsChanged; Visible = false; } mTarget = value; if (mTarget != null) { mTarget.VisibilityChanged += OnElementVisibilityChanged; mTarget.BoundsChanged += OnElementBoundsChanged; Visible = true; SetBounds(mTarget.Bounds); } } } public override void Draw(Graphics g) { Pen pen = new Pen(Color.Black, 1); pen.DashStyle = DashStyle.Dash; g.DrawRectangle(pen, new Rectangle(Bounds.X, Bounds.Y, Bounds.Width - 1, Bounds.Height - 1)); pen.Dispose(); } private void OnElementBoundsChanged(object o, BoundsChangedArgs args) { SetBounds(Target.Bounds); } private void OnElementVisibilityChanged(object o, System.EventArgs args) { if (!Target.Visible) Target = null; } } }