private void AddField(FieldForm fieldForm) { FormFieldCard lastCard = FindLastCard(); FormFieldCard card = new FormFieldCard() { //Question = fieldForm.Question.Value, CardWidth = mainPanel.Width - diffX, EditorMainPanel = mainPanel, MainControl = this, }; card.CardMouseMove += card_MouseMove; card.CardMouseUp += card_MouseUp; card.RemoveButtonClick += card_RemoveButtonClick; card.ChangeTopPanelVisibility(showTools); card.SetField(fieldForm.Field); if (lastCard != null) { lastCard.BelowCard = card; } mainPanel.Controls.Add(card); RedrawFormular(); card.Focus(); mainPanel.ScrollControlIntoView(card); }
/// <summary> /// Add or update in FormEditorControl /// </summary> /// <param name="field">Field to add</param> /// <param name="updateField">Specifies if the field has to be updated in the editor if was founded</param> /// /// <param name="addField">Specifies if the field has to be added into editor if was not founded</param> /// <returns></returns> public bool AddOrUpdateField(Field field, bool updateField, bool addField) { bool containsField = false; foreach (var item in mainPanel.Controls) { if (item is FormFieldCard cardItem && cardItem.Field.ID == field.ID) { if (cardItem.IsRemoved) { cardItem.RemoveCard(true); } else { if (updateField) { cardItem.SetField(field); } cardItem.Focus(); containsField = true; mainPanel.ScrollControlIntoView(cardItem); break; } } } if (!containsField && addField) { FormFieldCard lastCard = FindLastCard(); FormFieldCard card = new FormFieldCard() { CardWidth = mainPanel.Width - diffX, EditorMainPanel = mainPanel, MainControl = this, Question = field.Question }; card.CardMouseMove += card_MouseMove; card.CardMouseMove += card_MouseMove; card.CardMouseUp += card_MouseUp; card.RemoveButtonClick += card_RemoveButtonClick; card.ChangeTopPanelVisibility(showTools); card.SetField(field); if (lastCard != null) { lastCard.BelowCard = card; } mainPanel.Controls.Add(card); RedrawFormular(); mainPanel.ScrollControlIntoView(card); card.Focus(); AddCommand(new CardCommand(card, Enums.CardCommandEnum.Add)); } return(containsField); }
/// <summary> /// Loads EZKO formular into mainPanel of the FormEditorControl /// </summary> /// <param name="formular">Formular which has to be loaded</param> public void LoadFormular(DatabaseCommunicator.Model.Form formular) { if (formular == null) { return; } if (Commands == null) { Commands = new List <CardCommand>(); } mainPanel.Controls.Clear(); formNameLabel.Text = formular.Name; FormFieldCard lastAddedCard = null; foreach (var item in formular.FieldForms.Where(x => !x.Field.IsDeleted).OrderBy(x => x.Question.Index)) { FormFieldCard card = new FormFieldCard() { //Question = item.Question.Value, Question = item.Field.Question, CardWidth = mainPanel.Width - diffX, EditorMainPanel = mainPanel, MainControl = this, }; card.CardMouseMove += card_MouseMove; card.CardMouseUp += card_MouseUp; card.RemoveButtonClick += card_RemoveButtonClick; card.SetField(item.Field); if (lastAddedCard != null) { lastAddedCard.BelowCard = card; } lastAddedCard = card; mainPanel.Controls.Add(card); AddCommand(new CardCommand(card, Enums.CardCommandEnum.Add)); } RedrawFormular(); }