/// <summary> /// Finalizes editing the <see cref="EditModeItem"/>. /// </summary> /// <param name="cancel">Value indicating if edition of item should be canceled.</param> public void FinalizeEditMode(bool cancel) { if (!EditMode || EditModeItem == null || _finalizingEdition) return; _finalizingEdition = true; string cancelText = _editModeItem.Text; CalendarItem itemBuffer = _editModeItem; _editModeItem = null; CalendarItemCancelEventArgs evt = new CalendarItemCancelEventArgs(itemBuffer); if(!cancel) itemBuffer.Text = TextBox.Text.Trim(); if (TextBox != null) { TextBox.Visible = false; Controls.Remove(TextBox); TextBox.Dispose(); } if(_editModeItem != null) Invalidate(itemBuffer); _textBox = null; if (_creatingItem) { OnItemCreated(evt); } else { OnItemEdited(evt); } if (evt.Cancel) { itemBuffer.Text = cancelText; } _creatingItem = false; _finalizingEdition = false; if (State == CalendarState.EditingItemText) { SetState(CalendarState.Idle); } }
/// <summary> /// Activates the edit mode on the specified item /// </summary> /// <param name="item"></param> public void ActivateEditMode(CalendarItem item) { CalendarItemCancelEventArgs evt = new CalendarItemCancelEventArgs(item); if (!_creatingItem) { OnItemEditing(evt); } if (evt.Cancel) { return; } _editModeItem = item; TextBox = new CalendarTextBox(this); TextBox.KeyDown += new KeyEventHandler(TextBox_KeyDown); TextBox.LostFocus += new EventHandler(TextBox_LostFocus); Rectangle r = item.Bounds; r.Inflate(-2, -2); TextBox.Bounds = r; TextBox.BorderStyle = BorderStyle.None; TextBox.Text = item.Text; TextBox.Multiline = true; Controls.Add(TextBox); TextBox.Visible = true; TextBox.Focus(); TextBox.SelectionStart = TextBox.Text.Length; SetState(CalendarState.EditingItemText); }