commit 1f6b32de7d3a89855eb761ec36a653688a243567
parent 22dcaad6a66147c371b4ba21521b890061649099
Author: Minerva_juppiter <ryouturn@gmail.com>
Date: Sun, 17 Mar 2024 23:14:52 +0900
UIの枠線の追加や入力の厳格化など
Diffstat:
7 files changed, 115 insertions(+), 128 deletions(-)
diff --git a/App.config b/App.config
@@ -9,31 +9,31 @@
<userSettings>
<BusynessNotification.Properties.Settings>
<setting name="CheckCPU" serializeAs="String">
- <value>False</value>
+ <value>True</value>
</setting>
<setting name="CheckMemory" serializeAs="String">
- <value>False</value>
+ <value>True</value>
</setting>
<setting name="CheckDisk" serializeAs="String">
- <value>False</value>
+ <value>True</value>
</setting>
<setting name="SliderCPU" serializeAs="String">
- <value>0</value>
+ <value>50</value>
</setting>
<setting name="SliderMemory" serializeAs="String">
- <value>0</value>
+ <value>50</value>
</setting>
<setting name="SliderDisk" serializeAs="String">
- <value>0</value>
+ <value>50</value>
</setting>
<setting name="SecCPU" serializeAs="String">
- <value>0</value>
+ <value>10</value>
</setting>
<setting name="SecMemory" serializeAs="String">
- <value>0</value>
+ <value>10</value>
</setting>
<setting name="SecDisk" serializeAs="String">
- <value>0</value>
+ <value>10</value>
</setting>
</BusynessNotification.Properties.Settings>
<BusynessNotification.Settings1>
diff --git a/App.xaml.cs b/App.xaml.cs
@@ -19,33 +19,17 @@ namespace BusynessNotification
{
base.OnStartup(e);
///ここにスタートアップ時の処理を記述
- System.Windows.Forms.NotifyIcon notifyIcon;
- notifyIcon = new NotifyIcon();
- notifyIcon.Text = "BusynessNotification";
- notifyIcon.Visible = true;
-
- //アイコンにコンテキストメニュー「終了」を追加する
- ContextMenuStrip menuStrip = new ContextMenuStrip();
-
- ToolStripMenuItem exitItem = new ToolStripMenuItem();
- exitItem.Text = "終了";
- menuStrip.Items.Add(exitItem);
- exitItem.Click += new EventHandler(exitItem_Click);
- notifyIcon.ContextMenuStrip = menuStrip;
- notifyIcon.MouseClick += new System.Windows.Forms.MouseEventHandler(notifyIcon_MouseClick);
+ var icon = GetResourceStream(new Uri("BussynessNotificaion.ico", UriKind.Relative)).Stream;
+ var notifyIcon = new System.Windows.Forms.NotifyIcon
+ {
+ Visible = true,
+ Icon = new System.Drawing.Icon(icon),
+ Text = "BusynessNotification"
+ };
+ notifyIcon.MouseClick += new System.Windows.Forms.MouseEventHandler(NotifyIcon_Click);
ObserveUseage observeUseage = new ObserveUseage();
observeUseage.Controller();
-
- void exitItem_Click(object sender, EventArgs e)
- {
- try
- {
- notifyIcon.Dispose();
- System.Windows.Application.Current.Shutdown();
- }
- catch { }
- }
}
protected override void OnExit(ExitEventArgs e)
@@ -53,10 +37,13 @@ namespace BusynessNotification
base.OnExit(e);
}
- private void notifyIcon_MouseClick(object sender, System.Windows.Forms.MouseEventArgs e)
+ private void NotifyIcon_Click(object sender, System.Windows.Forms.MouseEventArgs e)
{
- var mainwindow = new MainWindow();
- mainwindow.Show();
+ if (e.Button == System.Windows.Forms.MouseButtons.Left)
+ {
+ var wnd = new MainWindow();
+ wnd.Show();
+ }
}
}
diff --git a/BusynessNotification.csproj b/BusynessNotification.csproj
@@ -10,7 +10,14 @@
</PropertyGroup>
<ItemGroup>
- <Reference Include="System.Windows.Forms" />
+ <None Remove="BussynessNotificaion.ico" />
+ </ItemGroup>
+
+ <ItemGroup>
+ <Reference Include="System.Windows.Forms">
+ <SpecificVersion>False</SpecificVersion>
+ <EmbedInteropTypes>True</EmbedInteropTypes>
+ </Reference>
</ItemGroup>
<ItemGroup>
@@ -18,6 +25,12 @@
</ItemGroup>
<ItemGroup>
+ <Resource Include="BussynessNotificaion.ico">
+ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+ </Resource>
+ </ItemGroup>
+
+ <ItemGroup>
<Compile Update="Properties\Settings.Designer.cs">
<DesignTimeSharedInput>True</DesignTimeSharedInput>
<AutoGen>True</AutoGen>
@@ -31,9 +44,6 @@
</ItemGroup>
<ItemGroup>
- <None Update="BussynessNotificaion.ico">
- <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
- </None>
<None Update="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
diff --git a/MainWindow.xaml b/MainWindow.xaml
@@ -8,7 +8,7 @@
xmlns:local="clr-namespace:BusynessNotification"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
- <Grid>
+ <Grid ShowGridLines="True">
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs
@@ -9,6 +9,7 @@ using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
+using System.Security.AccessControl;
namespace BusynessNotification
{
@@ -20,6 +21,36 @@ namespace BusynessNotification
public MainWindow()
{
InitializeComponent();
+
+ ///設定値の読み取り
+ bool CheckCPU = Properties.Settings.Default.CheckCPU;
+ bool CheckMemory = Properties.Settings.Default.CheckMemory;
+ bool CheckDisk = Properties.Settings.Default.CheckDisk;
+
+ double SliderCPU = Properties.Settings.Default.SliderCPU;
+ double SliderMemory = Properties.Settings.Default.SliderMemory;
+ double SliderDisk = Properties.Settings.Default.SliderDisk;
+
+ int SecCPU = Properties.Settings.Default.SecCPU;
+ int SecMemory = Properties.Settings.Default.SecMemory;
+ int SecDisk = Properties.Settings.Default.SecDisk;
+
+ ///取得した値をUIに適応
+ CPUcheck.IsChecked = CheckCPU;
+ Memorycheck.IsChecked = CheckMemory;
+ Diskcheck.IsChecked = CheckDisk;
+
+ CPUSlider.Value = SliderCPU;
+ MemorySlider.Value = SliderMemory;
+ DiskSlider.Value = SliderDisk;
+
+ TextBox_CPUSlider.Text = SliderCPU.ToString();
+ TextBox_DiskSlider.Text = SliderMemory.ToString();
+ TextBox_DiskSlider.Text = SliderDisk.ToString();
+
+ CPUSecTextBox.Text = SecCPU.ToString();
+ MemorySecTextBox.Text = SecMemory.ToString();
+ DiskSecTextBox.Text = SecDisk.ToString();
}
private void CPUSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
@@ -31,26 +62,12 @@ namespace BusynessNotification
private void TextBox_CPUSlider_TextChanged(object sender, TextChangedEventArgs e)
{
- if (TextBox_CPUSlider.ToString() != "")
- {
- double CPUvalue = double.Parse(TextBox_CPUSlider.Text);
- if (0 <= CPUvalue && CPUvalue <= 100)
- {
- CPUSlider.Value = CPUvalue;
- }
- }
+ TextBox_CPUSlider.Text = InputNormalizerToDouble(TextBox_CPUSlider.Text,Properties.Settings.Default.SliderCPU).ToString();
}
private void TextBox_MemorySlider_TextChanged(object sender, TextChangedEventArgs e)
{
- if (TextBox_CPUSlider.ToString() != "")
- {
- double Memoryvalue = double.Parse(TextBox_MemorySlider.Text);
- if (0 <= Memoryvalue && Memoryvalue <= 100)
- {
- MemorySlider.Value = Memoryvalue;
- }
- }
+ TextBox_MemorySlider.Text = InputNormalizerToDouble(TextBox_MemorySlider.Text,Properties.Settings.Default.SliderMemory).ToString();
}
private void MemorySlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
@@ -69,71 +86,22 @@ namespace BusynessNotification
private void TextBox_DiskSlider_TextChanged(object sender, TextChangedEventArgs e)
{
- if (TextBox_DiskSlider.Text.ToString() != "")
- {
- double Diskvalue = double.Parse (TextBox_DiskSlider.Text);
- if(0 <= Diskvalue && Diskvalue <= 100) {
- DiskSlider.Value = Diskvalue;
- }
- }
+ TextBox_CPUSlider.Text = InputNormalizerToDouble(TextBox_CPUSlider.Text.ToString(), Properties.Settings.Default.SliderDisk).ToString();
}
private void CPUSecTextBox_TextChanged(object sender, TextChangedEventArgs e)
{
- if (CPUSecTextBox.Text.ToString() != "")
- {
- int CPUSecValue = new int();
- bool CPUSecCan = int.TryParse (CPUSecTextBox.Text.ToString(),out CPUSecValue);
- if (CPUSecCan == false || CPUSecValue < 0 || CPUSecValue >= 1000)
- {
- string messageBoxText = "Please enter up to 3 digits?";
- string caption = "unexpected input";
- MessageBoxButton button = MessageBoxButton.OK;
- MessageBoxImage icon = MessageBoxImage.Warning;
- MessageBoxResult result;
-
- result = System.Windows.MessageBox.Show(messageBoxText, caption, button, icon);
- CPUSecTextBox.Text = CPUSecValue.ToString();
- }
- }
+ CPUSecTextBox.Text = InputNormalizerToDouble(CPUSecTextBox.Text,Properties.Settings.Default.SecCPU).ToString();
}
private void MemorySecTextBox_TextChanged(object sender, TextChangedEventArgs e)
{
- if (MemorySecTextBox.Text.ToString() != "")
- {
- int MemorySecValue = new int();
- bool MemorySecCan = int.TryParse(MemorySecTextBox.Text.ToString(), out MemorySecValue);
- if (MemorySecCan == false || MemorySecValue < 0 || MemorySecValue >= 1000)
- {
- string messageBoxText = "Please enter up to 3 digits?";
- string caption = "unexpected input";
- MessageBoxButton button = MessageBoxButton.OK;
- MessageBoxImage icon = MessageBoxImage.Warning;
- MessageBoxResult result;
-
- result = System.Windows.MessageBox.Show(messageBoxText, caption, button, icon);
- }
- }
+ MemorySecTextBox.Text = InputNormalizerToDouble(MemorySecTextBox.Text.ToString(), Properties.Settings.Default.SecMemory).ToString();
}
private void DiskSecTextBox_TextChanged(object sender, TextChangedEventArgs e)
{
- if (DiskSecTextBox.Text.ToString() != "")
- {
- int DiskSecValue = new int();
- bool DiskSecCan = int.TryParse(DiskSecTextBox.Text.ToString(), out DiskSecValue);
- if (DiskSecCan == false || DiskSecValue < 0 || DiskSecValue >= 1000)
- {
- string messageBoxText = "Please enter up to 3 digits?";
- string caption = "unexpected input";
- MessageBoxButton button = MessageBoxButton.OK;
- MessageBoxImage icon = MessageBoxImage.Warning;
- MessageBoxResult result;
-
- result = System.Windows.MessageBox.Show(messageBoxText, caption, button, icon);
- }
- }
+ DiskSecTextBox.Text = InputNormalizerToDouble(DiskSecTextBox.Text.ToString(), Properties.Settings.Default.SecDisk).ToString();
}
private void SaveSettingButton_Click(object sender, RoutedEventArgs e)
@@ -152,5 +120,27 @@ namespace BusynessNotification
Properties.Settings.Default.Save();
}
+
+ static double InputNormalizerToDouble(string input,double oldValue)
+ {
+ double value;
+ bool NormalizationCan = double.TryParse(input, out value);
+ if(NormalizationCan == false || value < 0 || value >= 1000)
+ {
+ string messageBoxText = "Please enter up to 3 digits?";
+ string caption = "unexpected input";
+ MessageBoxButton button = MessageBoxButton.OK;
+ MessageBoxImage icon = MessageBoxImage.Warning;
+ MessageBoxResult result;
+
+ result = System.Windows.MessageBox.Show(messageBoxText, caption, button, icon);
+ value = oldValue;
+ return value;
+ }
+ else
+ {
+ return value;
+ }
+ }
}
}
\ No newline at end of file
diff --git a/Properties/Settings.Designer.cs b/Properties/Settings.Designer.cs
@@ -25,7 +25,7 @@ namespace BusynessNotification.Properties {
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
- [global::System.Configuration.DefaultSettingValueAttribute("False")]
+ [global::System.Configuration.DefaultSettingValueAttribute("True")]
public bool CheckCPU {
get {
return ((bool)(this["CheckCPU"]));
@@ -37,7 +37,7 @@ namespace BusynessNotification.Properties {
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
- [global::System.Configuration.DefaultSettingValueAttribute("False")]
+ [global::System.Configuration.DefaultSettingValueAttribute("True")]
public bool CheckMemory {
get {
return ((bool)(this["CheckMemory"]));
@@ -49,7 +49,7 @@ namespace BusynessNotification.Properties {
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
- [global::System.Configuration.DefaultSettingValueAttribute("False")]
+ [global::System.Configuration.DefaultSettingValueAttribute("True")]
public bool CheckDisk {
get {
return ((bool)(this["CheckDisk"]));
@@ -61,7 +61,7 @@ namespace BusynessNotification.Properties {
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
- [global::System.Configuration.DefaultSettingValueAttribute("0")]
+ [global::System.Configuration.DefaultSettingValueAttribute("50")]
public double SliderCPU {
get {
return ((double)(this["SliderCPU"]));
@@ -73,7 +73,7 @@ namespace BusynessNotification.Properties {
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
- [global::System.Configuration.DefaultSettingValueAttribute("0")]
+ [global::System.Configuration.DefaultSettingValueAttribute("50")]
public double SliderMemory {
get {
return ((double)(this["SliderMemory"]));
@@ -85,7 +85,7 @@ namespace BusynessNotification.Properties {
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
- [global::System.Configuration.DefaultSettingValueAttribute("0")]
+ [global::System.Configuration.DefaultSettingValueAttribute("50")]
public double SliderDisk {
get {
return ((double)(this["SliderDisk"]));
@@ -97,7 +97,7 @@ namespace BusynessNotification.Properties {
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
- [global::System.Configuration.DefaultSettingValueAttribute("0")]
+ [global::System.Configuration.DefaultSettingValueAttribute("10")]
public int SecCPU {
get {
return ((int)(this["SecCPU"]));
@@ -109,7 +109,7 @@ namespace BusynessNotification.Properties {
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
- [global::System.Configuration.DefaultSettingValueAttribute("0")]
+ [global::System.Configuration.DefaultSettingValueAttribute("10")]
public int SecMemory {
get {
return ((int)(this["SecMemory"]));
@@ -121,7 +121,7 @@ namespace BusynessNotification.Properties {
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
- [global::System.Configuration.DefaultSettingValueAttribute("0")]
+ [global::System.Configuration.DefaultSettingValueAttribute("10")]
public int SecDisk {
get {
return ((int)(this["SecDisk"]));
diff --git a/Properties/Settings.settings b/Properties/Settings.settings
@@ -3,31 +3,31 @@
<Profiles />
<Settings>
<Setting Name="CheckCPU" Type="System.Boolean" Scope="User">
- <Value Profile="(Default)">False</Value>
+ <Value Profile="(Default)">True</Value>
</Setting>
<Setting Name="CheckMemory" Type="System.Boolean" Scope="User">
- <Value Profile="(Default)">False</Value>
+ <Value Profile="(Default)">True</Value>
</Setting>
<Setting Name="CheckDisk" Type="System.Boolean" Scope="User">
- <Value Profile="(Default)">False</Value>
+ <Value Profile="(Default)">True</Value>
</Setting>
<Setting Name="SliderCPU" Type="System.Double" Scope="User">
- <Value Profile="(Default)">0</Value>
+ <Value Profile="(Default)">50</Value>
</Setting>
<Setting Name="SliderMemory" Type="System.Double" Scope="User">
- <Value Profile="(Default)">0</Value>
+ <Value Profile="(Default)">50</Value>
</Setting>
<Setting Name="SliderDisk" Type="System.Double" Scope="User">
- <Value Profile="(Default)">0</Value>
+ <Value Profile="(Default)">50</Value>
</Setting>
<Setting Name="SecCPU" Type="System.Int32" Scope="User">
- <Value Profile="(Default)">0</Value>
+ <Value Profile="(Default)">10</Value>
</Setting>
<Setting Name="SecMemory" Type="System.Int32" Scope="User">
- <Value Profile="(Default)">0</Value>
+ <Value Profile="(Default)">10</Value>
</Setting>
<Setting Name="SecDisk" Type="System.Int32" Scope="User">
- <Value Profile="(Default)">0</Value>
+ <Value Profile="(Default)">10</Value>
</Setting>
</Settings>
</SettingsFile>
\ No newline at end of file