public virtual void CancelEdit() { if (mLabelEdit != null) { //Remove event handlers mLabelEdit.Complete -= new EventHandler(mLabelEdit_Complete); mLabelEdit.Cancel -= new EventHandler(mLabelEdit_Complete); mLabelEdit.Visible = false; this.Controls.Remove(mLabelEdit as System.Windows.Forms.Control); mLabelEdit = null; } }
public virtual ILabelEdit StartEdit(Label label) { if (label == null) throw new ArgumentNullException("Label may not be null."); if (label.Parent == null) throw new ModelException("Label cannot have null parent."); if (label.Parent.Container == null) throw new ModelException("Label Parent container cannot be null."); if (! (label.Parent is ILabelContainer)) throw new ModelException("Label Parent container must be an ILabelContainer object."); if (mLabelEdit != null) return mLabelEdit; //Set up control mLabelEdit = Runtime.CreateLabelEdit(); if (! (mLabelEdit is System.Windows.Forms.Control)) throw new ModelException("Label editor does not inherit from System.Windows.Forms.Control."); System.Windows.Forms.Control labelEdit = (System.Windows.Forms.Control) mLabelEdit; this.Controls.Add(labelEdit); mLabel = label; //Set up location and size Element parent = label.Parent; ILabelContainer container = (ILabelContainer) parent; PointF location = container.GetLabelLocation(); SizeF size = container.GetLabelSize(); //Offset the location for the container location = new PointF(location.X + parent.Rectangle.X + parent.Container.Offset.X,location.Y + parent.Rectangle.Y + parent.Container.Offset.Y); //Adjust the location and size to screen co-ordinates and pixels according to scale and units location = new PointF(location.X * Render.ScaleFactor, location.Y * Render.ScaleFactor); location = new PointF(location.X + DisplayRectangle.X,location.Y + DisplayRectangle.Y); size = new SizeF(size.Width * Render.ScaleFactor, size.Height * Render.ScaleFactor); //Adjust the location if the model is paged if (Paged) location = new PointF(location.X + RenderPaged.PagedOffset.X, location.Y + RenderPaged.PagedOffset.Y); labelEdit.Location = Point.Round(location); labelEdit.Size = Size.Round(size); labelEdit.Font = label.Font; labelEdit.Text = label.Text; if (label is TextLabel) mLabelEdit.StringFormat = ((TextLabel) label).GetStringFormat(); labelEdit.ForeColor = label.Color; labelEdit.BackColor = Color.White; mLabelEdit.Zoom = Zoom; mLabelEdit.SendEnd(); //Set autosize causing correct size if (parent is Link) mLabelEdit.AutoSize = Editing.AutoSizeMode.Horizontal; //Set event handlers mLabelEdit.Complete += new EventHandler(mLabelEdit_Complete); mLabelEdit.Cancel += new EventHandler(mLabelEdit_Complete); labelEdit.Visible = true; labelEdit.Focus(); return mLabelEdit; }