protected virtual void InitializeGUI() { this.MainContainer = new VerticalListContainer { Dock = DockStyle.Fill, AutoScroll = true, AutoSizeMode = AutoSizeMode.GrowAndShrink, Padding = new Padding(12), AutoScrollOffset = new Point(12, 12), BackgroundSource = Theme.BackgroundSource.Inherit }; this.Controls.Add(MainContainer); this.ControlPanel = new PropertyContainer { Text = "Serial Port", Height = 40, AutoScroll = false, MinimumSize = new Size(380, 20), MaximumSize = new Size(1200, int.MaxValue), FitContent = false, ControlsAlignment = HorizontalAlignment.Right, Padding = new Padding(3), Margin = new Padding(0, 0, 0, 12), Font = MainForm.HeaderFont }; MainContainer.Controls.Add(ControlPanel); this.TargetPortField = new DropdownInputField { Font = MainForm.MainFont, LabelText = "Target Port", Text = Properties.Settings.Default.SerialPort_LastPort }; ControlPanel.Controls.Add(TargetPortField); this.StartServerButton = new FlatButton { Text = "Start Server", Icon = Properties.Resources.play, IconOffset = 0, Padding = new Padding(6, 0, 6, 0), Font = MainForm.MainFont }; ControlPanel.Controls.Add(StartServerButton); this.ParametersPanel = new VerticalListContainer { AutoScroll = false, MinimumSize = new Size(380, 20), MaximumSize = new Size(1200, int.MaxValue), AutoSize = true, AutoSizeMode = AutoSizeMode.GrowAndShrink, Padding = new Padding(0), Margin = new Padding(0), }; MainContainer.Controls.Add(ParametersPanel); this.ParametersHeader = new PropertyContainer { Text = "", Height = 40, AutoScroll = false, MinimumSize = new Size(380, 20), MaximumSize = new Size(1200, int.MaxValue), FitContent = false, ControlsAlignment = HorizontalAlignment.Right, LabelAlignment = ContentAlignment.MiddleLeft, Padding = new Padding(3), Margin = new Padding(0), Font = MainForm.HeaderFont, LabelWidth = 75, }; ParametersPanel.Controls.Add(ParametersHeader); this.LoadServerSettingsButton = new FlatButton { Text = "", Size = new Size(32, 32), Icon = Properties.Resources.OpenFile, IconSize = 32, IconOffset = 0, Padding = new Padding(4), IconMultiplyColor = Color.FromArgb(215, 172, 106), Font = MainForm.MainFont, UseButtonBorder = false, BackgroundSource = Theme.BackgroundSource.Inherit }; ParametersHeader.Controls.Add(LoadServerSettingsButton); this.SaveServerSettingsButton = new FlatButton { Text = "", Size = new Size(32, 32), Icon = Properties.Resources.SaveFile, IconSize = 32, IconOffset = 0, Padding = new Padding(4), IconMultiplyColor = Color.FromArgb(114, 186, 236), Font = MainForm.MainFont, UseButtonBorder = false, BackgroundSource = Theme.BackgroundSource.Inherit }; ParametersHeader.Controls.Add(SaveServerSettingsButton); this.ParametersContainer = new FlexColumnContainer { AutoScroll = false, Height = 600, AutoSize = true, AutoSizeMode = AutoSizeMode.GrowAndShrink, ColumnsLayout = FlexColumnsLayoutEngine.ColumnsLayout.HorizontalStaggeredGrid, Padding = new Padding(0, 6, 0, 12), Margin = new Padding(0), MinColumnCount = 1, MaxColumnCount = 4, MinColumnSize = 260, MaxColumnSize = 0, }; ParametersPanel.Controls.Add(ParametersContainer); // Main Parameters Group this.MainParametersGroup = new VerticalListContainer { AutoScroll = false, AutoSize = true, AutoSizeMode = AutoSizeMode.GrowAndShrink, Padding = new Padding(0), Margin = new Padding(0), }; ParametersContainer.Controls.Add(MainParametersGroup); // Edit Data Property this.EditDataProperty = new PropertyContainer { Text = "Serial Port Data", Margin = new Padding(8, 1, 8, 1) }; MainParametersGroup.Controls.Add(EditDataProperty); this.EditDataButton = new FlatButton { Text = "Edit" }; EditDataProperty.Controls.Add(EditDataButton); // Port Speed Property this.PortSpeedProperty = new PropertyContainer { Text = "Port Speed", Margin = new Padding(8, 1, 8, 1) }; MainParametersGroup.Controls.Add(PortSpeedProperty); this.PortSpeedField = new Dropdown { }; PortSpeedField.FromEnum(Server.Settings.PortSpeed); PortSpeedProperty.Controls.Add(PortSpeedField); // Connection Parameters Group this.ConnectionParametersGroup = new VerticalListContainer { AutoScroll = false, AutoSize = true, AutoSizeMode = AutoSizeMode.GrowAndShrink, Padding = new Padding(0), Margin = new Padding(0), }; ParametersContainer.Controls.Add(ConnectionParametersGroup); // Auto Connect Property this.AutoConnectProperty = new PropertyContainer { Text = "Auto Connect", Margin = new Padding(8, 1, 8, 1) }; ConnectionParametersGroup.Controls.Add(AutoConnectProperty); this.AutoConnectToggle = new Toggle { Text = "", Style = Toggle.CheckmarkStyle.Toggle, }; AutoConnectProperty.Controls.Add(AutoConnectToggle); // Auto Connect Request Property this.AutoConnectRequestProperty = new PropertyContainer { Text = "Connection Request", Margin = new Padding(8, 1, 8, 1), Indent = 1 }; ConnectionParametersGroup.Controls.Add(AutoConnectRequestProperty); this.AutoConnectRequestField = new InputField { }; AutoConnectRequestProperty.Controls.Add(AutoConnectRequestField); // Auto Connect Response Property this.AutoConnectResponseProperty = new PropertyContainer { Text = "Connection Response", Margin = new Padding(8, 1, 8, 1), Indent = 1 }; ConnectionParametersGroup.Controls.Add(AutoConnectResponseProperty); this.AutoConnectResponseField = new InputField { }; AutoConnectResponseProperty.Controls.Add(AutoConnectResponseField); // Response Timeout Property this.AutoConnectResponseTimeoutProperty = new PropertyContainer { Text = "Response Timeout (ms)", Margin = new Padding(8, 1, 8, 1), Indent = 1 }; ConnectionParametersGroup.Controls.Add(AutoConnectResponseTimeoutProperty); this.AutoConnectResponseTimeoutField = new NumericInputField { Minimum = 100, Maximum = int.MaxValue, Increment = 50, }; AutoConnectResponseTimeoutProperty.Controls.Add(AutoConnectResponseTimeoutField); // Connection Interval Property this.ConnectionIntervalProperty = new PropertyContainer { Text = "Connection Interval (ms)", Margin = new Padding(8, 1, 8, 1), }; ConnectionParametersGroup.Controls.Add(ConnectionIntervalProperty); this.ConnectionIntervalField = new NumericInputField { Minimum = 100, Maximum = int.MaxValue, Increment = 50, }; ConnectionIntervalProperty.Controls.Add(ConnectionIntervalField); // Send Mode Parameters Group this.SendModeParametersGroup = new VerticalListContainer { AutoScroll = false, AutoSize = true, AutoSizeMode = AutoSizeMode.GrowAndShrink, Padding = new Padding(0), Margin = new Padding(0), }; ParametersContainer.Controls.Add(SendModeParametersGroup); // Send Mode Property this.SendModeProperty = new PropertyContainer { Text = "Send Mode", Margin = new Padding(8, 1, 8, 1) }; SendModeParametersGroup.Controls.Add(SendModeProperty); this.SendModeField = new Dropdown { }; SendModeField.FromEnum(Server.Settings.SendMode); SendModeProperty.Controls.Add(SendModeField); // Message Interval Property this.MessageIntervalProperty = new PropertyContainer { Text = "Message Interval (ms)", Margin = new Padding(8, 1, 8, 1), Indent = 1 }; SendModeParametersGroup.Controls.Add(MessageIntervalProperty); this.MessageIntervalField = new NumericInputField { Minimum = 100, Maximum = int.MaxValue, Increment = 50, }; MessageIntervalProperty.Controls.Add(MessageIntervalField); // Message Interval Property this.ConnectionCheckProperty = new PropertyContainer { Text = "Connection Check (ms)", Margin = new Padding(8, 1, 8, 1), Indent = 1 }; SendModeParametersGroup.Controls.Add(ConnectionCheckProperty); this.ConnectionCheckField = new NumericInputField { Minimum = 100, Maximum = int.MaxValue, Increment = 50, }; ConnectionCheckProperty.Controls.Add(ConnectionCheckField); // Data Request Property this.DataRequestProperty = new PropertyContainer { Text = "Data Request", Margin = new Padding(8, 1, 8, 1), Indent = 1 }; SendModeParametersGroup.Controls.Add(DataRequestProperty); this.DataRequestField = new InputField { }; DataRequestProperty.Controls.Add(DataRequestField); }
protected virtual void InitializeHandles() { StartServerButton.Click += (object sender, EventArgs e) => { if (Server.ServerState == Servers.ServerState.Stop) { Server?.Begin(); } else { Server?.Stop(); } }; TargetPortField.DropDown += (object sender, EventArgs e) => { if (sender is DropdownInputField) { DropdownInputField dropdown = sender as DropdownInputField; List <string> availablePorts = Server.GetAvailablePorts(); if (availablePorts == null) { return; } dropdown.Items.Clear(); dropdown.Items.AddRange(availablePorts); } }; TargetPortField.ItemSelected += (object sender, ItemEventArgs e) => { string port = TargetPortField.Text; Server.TargetPort = port; Properties.Settings.Default.SerialPort_LastPort = port; Properties.Settings.Default.Save(); }; TargetPortField.Leave += (object sender, EventArgs e) => { string port = TargetPortField.Text; Server.TargetPort = port; Properties.Settings.Default.SerialPort_LastPort = port; Properties.Settings.Default.Save(); }; SaveServerSettingsButton.Click += (object sender, EventArgs e) => { string projectPath = ProjectsUtils.ShowSaveProjectDialog(Server.Settings); if (projectPath != null) { Properties.Settings.Default.SerialPort_LastProject = projectPath; Properties.Settings.Default.Save(); } }; LoadServerSettingsButton.Click += (object sender, EventArgs e) => { SerialPortProject newProject = Server.Settings; string projectPath = ProjectsUtils.ShowOpenProjectDialog(ref newProject); if (projectPath != null) { Properties.Settings.Default.SerialPort_LastProject = projectPath; Properties.Settings.Default.Save(); } if (Server.Settings != newProject) { Server.Settings = newProject; } }; EditDataButton.Click += (object sender, EventArgs e) => { MainForm.ShowControl(CreateLogDataEditor()); }; PortSpeedField.ItemSelected += (object sender, ItemEventArgs e) => { Server.Settings.PortSpeed = PortSpeedField.ToEnum(Server.Settings.PortSpeed); UpdateValues(); }; AutoConnectToggle.Click += (object sender, EventArgs e) => { Server.Settings.AutoConnect = AutoConnectToggle.Checked; UpdateValues(); }; AutoConnectRequestField.Leave += (object sender, EventArgs e) => { Server.Settings.AutoConnectRequest = AutoConnectRequestField.Text; UpdateValues(); }; AutoConnectResponseField.Leave += (object sender, EventArgs e) => { Server.Settings.AutoConnectResponse = AutoConnectResponseField.Text; UpdateValues(); }; EventHandler autoConnectResponseTimeoutHandler = (object sender, EventArgs e) => { Server.Settings.AutoConnectResponseTimeout = (int)AutoConnectResponseTimeoutField.Value; UpdateValues(); }; AutoConnectResponseTimeoutField.Leave += autoConnectResponseTimeoutHandler; AutoConnectResponseTimeoutField.AddButton.Click += autoConnectResponseTimeoutHandler; AutoConnectResponseTimeoutField.SubtractButton.Click += autoConnectResponseTimeoutHandler; EventHandler connectionIntervalHandler = (object sender, EventArgs e) => { Server.Settings.ConnectionInterval = (int)ConnectionIntervalField.Value; UpdateValues(); }; ConnectionIntervalField.Leave += connectionIntervalHandler; ConnectionIntervalField.AddButton.Click += connectionIntervalHandler; ConnectionIntervalField.SubtractButton.Click += connectionIntervalHandler; SendModeField.ItemSelected += (object sender, ItemEventArgs e) => { Server.Settings.SendMode = SendModeField.ToEnum(Server.Settings.SendMode); UpdateValues(); }; EventHandler connectionCheckHandler = (object sender, EventArgs e) => { Server.Settings.ConnectionCheckInterval = (int)ConnectionCheckField.Value; UpdateValues(); }; ConnectionCheckField.Leave += connectionCheckHandler; ConnectionCheckField.AddButton.Click += connectionCheckHandler; ConnectionCheckField.SubtractButton.Click += connectionCheckHandler; EventHandler messageIntervalHandler = (object sender, EventArgs e) => { Server.Settings.MessageInterval = (int)MessageIntervalField.Value; UpdateValues(); }; MessageIntervalField.Leave += messageIntervalHandler; MessageIntervalField.AddButton.Click += messageIntervalHandler; MessageIntervalField.SubtractButton.Click += messageIntervalHandler; DataRequestField.Leave += (object sender, EventArgs e) => { Server.Settings.DataRequest = DataRequestField.Text; UpdateValues(); }; Properties.Settings.Default.PropertyChanged += (object sender, PropertyChangedEventArgs e) => { switch (e.PropertyName) { case "SerialPort_PortsWhitelist": Server.PortWhitelist.Clear(); Server.PortWhitelist.AddRange(SlicePortList(Properties.Settings.Default.SerialPort_PortWhitelist)); break; case "SerialPort_PortsBlacklist": Server.PortBlacklist.Clear(); Server.PortBlacklist.AddRange(SlicePortList(Properties.Settings.Default.SerialPort_PortBlacklist)); break; } }; }