source: branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/Views/JsonItemBaseControl.cs @ 17829

Last change on this file since 17829 was 17829, checked in by dpiringe, 3 months ago

#3026

  • moved JsonItems from Models to JsonItems
  • moved WinForms controls from Shared to Views
File size: 1.4 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.ComponentModel;
4using System.Drawing;
5using System.Data;
6using System.Linq;
7using System.Text;
8using System.Threading.Tasks;
9using System.Windows.Forms;
10
11namespace HeuristicLab.JsonInterface.OptimizerIntegration {
12  public partial class JsonItemBaseControl : UserControl {
13    protected IJsonItemVM VM { get; set; }
14
15    private JsonItemBaseControl() {
16      InitializeComponent();
17    }
18   
19    public JsonItemBaseControl(IJsonItemVM vm) {
20      InitializeComponent();
21      VM = vm;
22      Init();
23    }
24
25    public JsonItemBaseControl(IJsonItemVM vm, UserControl control) {
26      InitializeComponent();
27      VM = vm;
28      if(control != null) {
29        control.Margin = new Padding() { All = 0 };
30        tableLayoutPanel1.Controls.Add(control, 0, 1);
31        control.Dock = DockStyle.Fill;
32      }
33      Init();
34    }
35
36    private void Init() {
37      textBoxName.DataBindings.Add("Text", VM, nameof(IJsonItemVM.Name));
38      textBoxDescription.DataBindings.Add("Text", VM, nameof(IJsonItemVM.Description));
39    }
40
41    private void textBoxName_Validating(object sender, CancelEventArgs e) {
42      if(string.IsNullOrWhiteSpace(textBoxName.Text)) {
43        errorProvider.SetError(textBoxName, "Name must not be empty.");
44        e.Cancel = true;
45      } else {
46        errorProvider.SetError(textBoxName, null);
47      }
48    }
49  }
50}
Note: See TracBrowser for help on using the repository browser.