BusynessNotification

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit fe0bc430182c3a335b5354ea0a5ea4a37fc0b420
parent 63c919d57fd9202da0dccfb66f27d0b1606ffa83
Author: Minerva_juppiter <ryouturn@gmail.com>
Date:   Sat, 16 Mar 2024 23:39:37 +0900

タスクトレイのアイコンから起動を可能にした

Diffstat:
MApp.xaml.cs | 46+++++++++++++++++++++++++++++++++++++++++++++-
ABussynessNotificaion.ico | 0
MBusynessNotification.csproj | 8++++++++
MMainWindow.xaml.cs | 6+++---
MObserveUseage.cs | 4++--
MREADME.md | 2++
6 files changed, 60 insertions(+), 6 deletions(-)

diff --git a/App.xaml.cs b/App.xaml.cs @@ -1,18 +1,62 @@ using System.Configuration; using System.Data; +using System.Drawing; using System.Windows; +using System.Windows.Forms; namespace BusynessNotification { + + /// <summary> /// Interaction logic for App.xaml /// </summary> - public partial class App : Application + /// + + public partial class App : System.Windows.Application { protected override void OnStartup(StartupEventArgs e) { 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); + + 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) + { + base.OnExit(e); + } + + private void notifyIcon_MouseClick(object sender, System.Windows.Forms.MouseEventArgs e) + { + var mainwindow = new MainWindow(); + mainwindow.Show(); } } diff --git a/BussynessNotificaion.ico b/BussynessNotificaion.ico Binary files differ. diff --git a/BusynessNotification.csproj b/BusynessNotification.csproj @@ -6,9 +6,14 @@ <Nullable>enable</Nullable> <ImplicitUsings>enable</ImplicitUsings> <UseWPF>true</UseWPF> + <UseWindowsForms>true</UseWindowsForms>  </PropertyGroup> <ItemGroup> + <Reference Include="System.Windows.Forms" /> + </ItemGroup> + + <ItemGroup> <PackageReference Include="ModernWpfUI" Version="0.9.6" /> </ItemGroup> @@ -26,6 +31,9 @@ </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.cs b/MainWindow.xaml.cs @@ -92,7 +92,7 @@ namespace BusynessNotification MessageBoxImage icon = MessageBoxImage.Warning; MessageBoxResult result; - result = MessageBox.Show(messageBoxText, caption, button, icon); + result = System.Windows.MessageBox.Show(messageBoxText, caption, button, icon); CPUSecTextBox.Text = CPUSecValue.ToString(); } } @@ -112,7 +112,7 @@ namespace BusynessNotification MessageBoxImage icon = MessageBoxImage.Warning; MessageBoxResult result; - result = MessageBox.Show(messageBoxText, caption, button, icon); + result = System.Windows.MessageBox.Show(messageBoxText, caption, button, icon); } } } @@ -131,7 +131,7 @@ namespace BusynessNotification MessageBoxImage icon = MessageBoxImage.Warning; MessageBoxResult result; - result = MessageBox.Show(messageBoxText, caption, button, icon); + result = System.Windows.MessageBox.Show(messageBoxText, caption, button, icon); } } } diff --git a/ObserveUseage.cs b/ObserveUseage.cs @@ -43,7 +43,7 @@ namespace BusynessNotification Disc1.CounterName = "Disk Transfers/sec"; Disc1.InstanceName = "C:"; - Timer timer = null; + System.Threading.Timer timer = null; TimerCallback timer_delegate = async state => { @@ -84,7 +84,7 @@ namespace BusynessNotification timer.Dispose(); } }; - timer = new Timer(timer_delegate,null,1000,1000); + timer = new System.Threading.Timer(timer_delegate,null,1000,1000); } diff --git a/README.md b/README.md @@ -25,3 +25,5 @@ https://learn.microsoft.com/ja-jp/dotnet/desktop/winforms/advanced/how-to-write- timer.thread.timer https://atmarkit.itmedia.co.jp/ait/articles/0511/11/news118.html +^XNgCACR +https://qiita.com/kyv28v/items/0a5b078d246000cb6781