Permalink
Browse files

Add settings save and load functionality

  • Loading branch information...
NiceCircuits committed Nov 23, 2015
1 parent 515d533 commit 28fa81fa1e060ea941b27745c76fd27a5c0ae6b2
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>

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
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();
}
}
}

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -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>
View
@@ -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.
}
}
}
View
@@ -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.