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); }