Permalink
Browse files

Add settings save and load functionality

  • Loading branch information...
1 parent 515d533 commit 28fa81fa1e060ea941b27745c76fd27a5c0ae6b2 @NiceCircuits committed Nov 23, 2015
View
@@ -1,2 +1,3 @@
DualTerminal/obj
/DualTerminal/bin/Debug
+/DualTerminal/bin/Release/DualTerminal.pdb
View
Binary file not shown.
@@ -13,6 +13,7 @@
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
<FileAlignment>512</FileAlignment>
+ <IsWebBootstrapper>false</IsWebBootstrapper>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
@@ -25,7 +26,6 @@
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
- <IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
@@ -69,6 +69,7 @@
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="Settings.cs" />
<EmbeddedResource Include="Form1.resx">
<DependentUpon>Form1.cs</DependentUpon>
</EmbeddedResource>
@@ -82,6 +83,7 @@
<DependentUpon>Resources.resx</DependentUpon>
<DesignTime>True</DesignTime>
</Compile>
+ <None Include="app.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
@@ -45,11 +45,11 @@ private void InitializeComponent()
this.splitContainer1 = new System.Windows.Forms.SplitContainer();
this.richTextBox1 = new System.Windows.Forms.RichTextBox();
this.splitContainer2 = new System.Windows.Forms.SplitContainer();
- this.textBox1 = new System.Windows.Forms.TextBox();
- this.textBox2 = new System.Windows.Forms.TextBox();
+ this.button1 = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
+ this.textBox1 = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
- this.button1 = new System.Windows.Forms.Button();
+ this.textBox2 = new System.Windows.Forms.TextBox();
this.menuStrip1.SuspendLayout();
this.statusStrip1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit();
@@ -220,23 +220,14 @@ private void InitializeComponent()
this.splitContainer2.SplitterDistance = 541;
this.splitContainer2.TabIndex = 0;
//
- // textBox1
- //
- this.textBox1.Dock = System.Windows.Forms.DockStyle.Bottom;
- this.textBox1.ForeColor = System.Drawing.Color.Red;
- this.textBox1.Location = new System.Drawing.Point(0, 25);
- this.textBox1.Name = "textBox1";
- this.textBox1.Size = new System.Drawing.Size(541, 20);
- this.textBox1.TabIndex = 0;
- //
- // textBox2
+ // button1
//
- this.textBox2.Dock = System.Windows.Forms.DockStyle.Bottom;
- this.textBox2.ForeColor = System.Drawing.Color.Blue;
- this.textBox2.Location = new System.Drawing.Point(0, 25);
- this.textBox2.Name = "textBox2";
- this.textBox2.Size = new System.Drawing.Size(537, 20);
- this.textBox2.TabIndex = 1;
+ this.button1.Location = new System.Drawing.Point(416, 2);
+ this.button1.Name = "button1";
+ this.button1.Size = new System.Drawing.Size(75, 23);
+ this.button1.TabIndex = 2;
+ this.button1.Text = "button1";
+ this.button1.UseVisualStyleBackColor = true;
//
// label1
//
@@ -248,6 +239,15 @@ private void InitializeComponent()
this.label1.TabIndex = 1;
this.label1.Text = "Send to port1";
//
+ // textBox1
+ //
+ this.textBox1.Dock = System.Windows.Forms.DockStyle.Bottom;
+ this.textBox1.ForeColor = System.Drawing.Color.Red;
+ this.textBox1.Location = new System.Drawing.Point(0, 25);
+ this.textBox1.Name = "textBox1";
+ this.textBox1.Size = new System.Drawing.Size(541, 20);
+ this.textBox1.TabIndex = 0;
+ //
// label2
//
this.label2.AutoSize = true;
@@ -258,14 +258,14 @@ private void InitializeComponent()
this.label2.TabIndex = 1;
this.label2.Text = "Send to port2";
//
- // button1
+ // textBox2
//
- this.button1.Location = new System.Drawing.Point(416, 2);
- this.button1.Name = "button1";
- this.button1.Size = new System.Drawing.Size(75, 23);
- this.button1.TabIndex = 2;
- this.button1.Text = "button1";
- this.button1.UseVisualStyleBackColor = true;
+ this.textBox2.Dock = System.Windows.Forms.DockStyle.Bottom;
+ this.textBox2.ForeColor = System.Drawing.Color.Blue;
+ this.textBox2.Location = new System.Drawing.Point(0, 25);
+ this.textBox2.Name = "textBox2";
+ this.textBox2.Size = new System.Drawing.Size(537, 20);
+ this.textBox2.TabIndex = 1;
//
// Form1
//
View
@@ -18,11 +18,14 @@ public Form1()
InitializeComponent();
toolStripComboBoxBaud.SelectedIndex = 4;
int nPorts = refreshPorts();
- if (nPorts >= 2)
- {
- toolStripComboBoxPort1.SelectedIndex = 0;
- toolStripComboBoxPort2.SelectedIndex = 1;
- }
+ //if (nPorts >= 2)
+ //{
+ // toolStripComboBoxPort1.SelectedIndex = 0;
+ // toolStripComboBoxPort2.SelectedIndex = 1;
+ //}
+ toolStripComboBoxPort1.Text = Properties.Settings.Default.port1;
+ toolStripComboBoxPort2.Text = Properties.Settings.Default.port2;
+ toolStripComboBoxBaud.Text = Properties.Settings.Default.baudrate.ToString();
}
// Append text of the given color.
@@ -93,10 +96,10 @@ private void openToolStripMenuItem_Click(object sender=null, EventArgs e=null)
{
try
{
- serialPort1.PortName = toolStripComboBoxPort1.SelectedItem.ToString();
- serialPort2.PortName = toolStripComboBoxPort2.SelectedItem.ToString();
- serialPort1.BaudRate = Int32.Parse(toolStripComboBoxBaud.SelectedItem.ToString());
- serialPort2.BaudRate = Int32.Parse(toolStripComboBoxBaud.SelectedItem.ToString());
+ serialPort1.PortName = toolStripComboBoxPort1.Text;
+ serialPort2.PortName = toolStripComboBoxPort2.Text;
+ serialPort1.BaudRate = Int32.Parse(toolStripComboBoxBaud.Text);
+ serialPort2.BaudRate = Int32.Parse(toolStripComboBoxBaud.Text);
serialPort1.Open();
serialPort2.Open();
openToolStripMenuItem.Enabled = false;
@@ -130,6 +133,10 @@ private void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
closeToolStripMenuItem_Click();
+ Properties.Settings.Default.port1 = toolStripComboBoxPort1.Text;
+ Properties.Settings.Default.port2 = toolStripComboBoxPort2.Text;
+ Properties.Settings.Default.baudrate = Int32.Parse(toolStripComboBoxBaud.Text);
+ Properties.Settings.Default.Save();
}
private void serialPort2_DataReceived(object sender, SerialDataReceivedEventArgs e)
@@ -141,5 +148,7 @@ private void clearToolStripMenuItem_Click(object sender, EventArgs e)
{
richTextBox1.Clear();
}
+
+
}
}
@@ -22,5 +22,41 @@ internal sealed partial class Settings : global::System.Configuration.Applicatio
return defaultInstance;
}
}
+
+ [global::System.Configuration.UserScopedSettingAttribute()]
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ [global::System.Configuration.DefaultSettingValueAttribute("COM1")]
+ public string port1 {
+ get {
+ return ((string)(this["port1"]));
+ }
+ set {
+ this["port1"] = value;
+ }
+ }
+
+ [global::System.Configuration.UserScopedSettingAttribute()]
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ [global::System.Configuration.DefaultSettingValueAttribute("COM2")]
+ public string port2 {
+ get {
+ return ((string)(this["port2"]));
+ }
+ set {
+ this["port2"] = value;
+ }
+ }
+
+ [global::System.Configuration.UserScopedSettingAttribute()]
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ [global::System.Configuration.DefaultSettingValueAttribute("9600")]
+ public int baudrate {
+ get {
+ return ((int)(this["baudrate"]));
+ }
+ set {
+ this["baudrate"] = value;
+ }
+ }
}
}
@@ -1,7 +1,15 @@
<?xml version='1.0' encoding='utf-8'?>
-<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)">
- <Profiles>
- <Profile Name="(Default)" />
- </Profiles>
- <Settings />
-</SettingsFile>
+<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="DualTerminal.Properties" GeneratedClassName="Settings">
+ <Profiles />
+ <Settings>
+ <Setting Name="port1" Type="System.String" Scope="User">
+ <Value Profile="(Default)">COM1</Value>
+ </Setting>
+ <Setting Name="port2" Type="System.String" Scope="User">
+ <Value Profile="(Default)">COM2</Value>
+ </Setting>
+ <Setting Name="baudrate" Type="System.Int32" Scope="User">
+ <Value Profile="(Default)">9600</Value>
+ </Setting>
+ </Settings>
+</SettingsFile>
@@ -0,0 +1,28 @@
+namespace DualTerminal.Properties {
+
+
+ // This class allows you to handle specific events on the settings class:
+ // The SettingChanging event is raised before a setting's value is changed.
+ // The PropertyChanged event is raised after a setting's value is changed.
+ // The SettingsLoaded event is raised after the setting values are loaded.
+ // The SettingsSaving event is raised before the setting values are saved.
+ internal sealed partial class Settings {
+
+ public Settings() {
+ // // To add event handlers for saving and changing settings, uncomment the lines below:
+ //
+ // this.SettingChanging += this.SettingChangingEventHandler;
+ //
+ // this.SettingsSaving += this.SettingsSavingEventHandler;
+ //
+ }
+
+ private void SettingChangingEventHandler(object sender, System.Configuration.SettingChangingEventArgs e) {
+ // Add code to handle the SettingChangingEvent event here.
+ }
+
+ private void SettingsSavingEventHandler(object sender, System.ComponentModel.CancelEventArgs e) {
+ // Add code to handle the SettingsSaving event here.
+ }
+ }
+}
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<configuration>
+ <configSections>
+ <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
+ <section name="DualTerminal.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
+ </sectionGroup>
+ </configSections>
+ <userSettings>
+ <DualTerminal.Properties.Settings>
+ <setting name="port1" serializeAs="String">
+ <value>COM1</value>
+ </setting>
+ <setting name="port2" serializeAs="String">
+ <value>COM2</value>
+ </setting>
+ <setting name="baudrate" serializeAs="String">
+ <value>9600</value>
+ </setting>
+ </DualTerminal.Properties.Settings>
+ </userSettings>
+</configuration>
Binary file not shown.
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<configuration>
+ <configSections>
+ <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
+ <section name="DualTerminal.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
+ </sectionGroup>
+ </configSections>
+ <userSettings>
+ <DualTerminal.Properties.Settings>
+ <setting name="port1" serializeAs="String">
+ <value>COM1</value>
+ </setting>
+ <setting name="port2" serializeAs="String">
+ <value>COM2</value>
+ </setting>
+ <setting name="baudrate" serializeAs="String">
+ <value>9600</value>
+ </setting>
+ </DualTerminal.Properties.Settings>
+ </userSettings>
+</configuration>

0 comments on commit 28fa81f

Please sign in to comment.