-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
55 lines (53 loc) · 1.82 KB
/
Program.cs
File metadata and controls
55 lines (53 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using System;
using System.Windows.Forms;
using System.Drawing;
using System.Globalization;
using System.Linq;
namespace ClipboardCharCountNotify
{
class Program
{
[STAThread]
static void Main(string[] args)
{
var notify = new NotifyIcon
{
Icon = SystemIcons.Information,
Visible = true
};
try
{
if (Clipboard.ContainsText())
{
string text = Clipboard.GetText();
if (!string.IsNullOrEmpty(text))
{
// 改行をカウントせず、空白はカウントする
int charCount = text
.Where(c => c != '\r' && c != '\n') // 改行文字(CR, LF)を除外
.Count(c => !char.IsControl(c) && c != '\u200B'); // 制御文字とゼロ幅スペースを除外
notify.ShowBalloonTip(3000, "", $"クリップボード文字数: {charCount}", ToolTipIcon.Info);
}
else
{
notify.ShowBalloonTip(3000, "", "テキストデータがありません", ToolTipIcon.Info);
}
}
else
{
notify.ShowBalloonTip(3000, "", "テキストデータがありません", ToolTipIcon.Info);
}
}
catch (Exception ex)
{
notify.ShowBalloonTip(3000, "", $"エラー: {ex.Message}", ToolTipIcon.Error);
}
finally
{
System.Threading.Thread.Sleep(3000);
notify.Visible = false;
notify.Dispose();
}
}
}
}