Skip to content

Commit

Permalink
增加是否电池电量充至100%隐藏托盘图标配置项
Browse files Browse the repository at this point in the history
  • Loading branch information
shiqimei committed Jun 14, 2018
1 parent 86a3e29 commit 0ced5fe
Show file tree
Hide file tree
Showing 17 changed files with 104 additions and 26 deletions.
Binary file modified .vs/percentage/v15/.suo
Binary file not shown.
Binary file modified .vs/percentage/v15/Server/sqlite3/storage.ide
Binary file not shown.
Binary file modified .vs/percentage/v15/Server/sqlite3/storage.ide-shm
Binary file not shown.
Binary file modified .vs/percentage/v15/Server/sqlite3/storage.ide-wal
Binary file not shown.
58 changes: 43 additions & 15 deletions percentage/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 33 additions & 1 deletion percentage/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public Settings()
lgn.SetValue("normalColor", "255, 255, 255", RegistryValueKind.String);
lgn.SetValue("chargingColor", "254, 190, 4", RegistryValueKind.String);
lgn.SetValue("lowColor", "254, 97, 82", RegistryValueKind.String);
lgn.SetValue("autoHide", "false", RegistryValueKind.String); // 电池电量充满后是否自动隐藏
}
RegistryKey lgn1 = hklm.OpenSubKey(@"Software\BatteryIcon", true);
// 从注册表获取数据
Expand Down Expand Up @@ -193,11 +194,42 @@ private void label7_Click(object sender, EventArgs e)
MatchCollection matchs = reg.Matches(s);

string filename = "";
if (matchs.Count > 0) //www.2cto.com
if (matchs.Count > 0)
{
filename = matchs[0].Groups[1].Value;
System.Diagnostics.Process.Start(filename, "https://github.com/loliMay/PercentageBatteryIcon");
}
}

private void label8_Click(object sender, EventArgs e)
{

}

private void label9_Click(object sender, EventArgs e)
{

}

private void Settings_Load(object sender, EventArgs e)
{

}

// 电池电量充满后是否自动隐藏电池图标
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
RegistryKey hklm = Registry.CurrentUser;
RegistryKey lgn = hklm.OpenSubKey(@"Software\BatteryIcon", true);
if (checkBox1.Checked == true)
{
TrayIcon.autoHide = "true";
lgn.SetValue("autoHide", "true", RegistryValueKind.String);
} else
{
TrayIcon.autoHide = "false";
lgn.SetValue("autoHide", "false", RegistryValueKind.String);
}
}
}
}
26 changes: 22 additions & 4 deletions percentage/TrayIcon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ class TrayIcon
public static Color normalColor = Color.FromArgb(255, 255, 255); // 主颜色
public static Color chargingColor = Color.FromArgb(254, 190, 4); // 充电时颜色
public static Color lowColor = Color.FromArgb(254, 97, 82); // 低电量时颜色
public static int isHideIcon = 1;
public static int isShowPercent = 0;
public static string autoHide;

private string batteryPercentage;
private NotifyIcon notifyIcon;
Expand All @@ -40,6 +43,7 @@ public TrayIcon()
string normal = lgn.GetValue("normalColor").ToString();
string charging = lgn.GetValue("chargingColor").ToString();
string low = lgn.GetValue("lowColor").ToString();
autoHide = lgn.GetValue("autoHide").ToString();
try
{
iconFontSize = Convert.ToInt32(fontsize); // 从字符串获取字体大小
Expand Down Expand Up @@ -94,12 +98,26 @@ private void timer_Tick(object sender, EventArgs e)
PowerStatus powerStatus = SystemInformation.PowerStatus;
batteryPercentage = (powerStatus.BatteryLifePercent * 100).ToString();

// 从注册表加载偏移信息
RegistryKey hklm = Registry.CurrentUser;
RegistryKey lgn = hklm.OpenSubKey(@"Software\BatteryIcon", true);
iconFontSize = Convert.ToInt32(lgn.GetValue("fontsize").ToString()); // 更新信息
xoffset = Convert.ToInt32(lgn.GetValue("xoffset").ToString());
yoffset = Convert.ToInt32(lgn.GetValue("yoffset").ToString());

// 如果电量充满则不显示
if(batteryPercentage == "100")
if (batteryPercentage == "100" && autoHide == "true")
{
notifyIcon.Visible = false;
notifyIcon.Visible = false;
} else
{
if (batteryPercentage == "100")
{
iconFontSize = 23;
xoffset = -10;
yoffset = 5;
batteryPercentage = "100";
}
notifyIcon.Visible = true;
}

Expand All @@ -116,7 +134,7 @@ private void timer_Tick(object sender, EventArgs e)
{
batteryColor = normalColor;
}
}
} // 渲染字体内容
using (Bitmap bitmap = new Bitmap(DrawText(batteryPercentage, new Font(iconFont, iconFontSize), batteryColor, Color.Transparent))) // 背景色透明
{
IntPtr intPtr = bitmap.GetHicon();
Expand Down Expand Up @@ -176,7 +194,7 @@ private Image DrawText(String text, Font font, Color textColor, Color backColor)

private static SizeF GetImageSize(string text, Font font)
{
using (Image image = new Bitmap(10, 10))
using (Image image = new Bitmap(32, 32))
using (Graphics graphics = Graphics.FromImage(image))
return graphics.MeasureString(text, font);
}
Expand Down
Binary file modified percentage/bin/Debug/app.publish/百分比电池图标.exe
Binary file not shown.
2 changes: 1 addition & 1 deletion percentage/bin/Debug/百分比电池图标.application
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
</dsig:Transforms>
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha256" />
<dsig:DigestValue>RswnWJn/IbDfM9cCZnXVeTnIGdjkRcFw2AciWLkT9yY=</dsig:DigestValue>
<dsig:DigestValue>dU1VGpU3B/XGnMs7s0ROwPXQC1+qIyEEQS2Nl+bM6To=</dsig:DigestValue>
</hash>
</dependentAssembly>
</dependency>
Expand Down
Binary file modified percentage/bin/Debug/百分比电池图标.exe
Binary file not shown.
4 changes: 2 additions & 2 deletions percentage/bin/Debug/百分比电池图标.exe.manifest
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@
</dependentAssembly>
</dependency>
<dependency>
<dependentAssembly dependencyType="install" allowDelayedBinding="true" codebase="百分比电池图标.exe" size="94720">
<dependentAssembly dependencyType="install" allowDelayedBinding="true" codebase="百分比电池图标.exe" size="95744">
<assemblyIdentity name="百分比电池图标" version="1.0.0.0" language="neutral" processorArchitecture="msil" />
<hash>
<dsig:Transforms>
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
</dsig:Transforms>
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha256" />
<dsig:DigestValue>MSjlqJ3kqysEPzxDLk1aCFXkoWeh5p9GjnriucqNWCg=</dsig:DigestValue>
<dsig:DigestValue>F1G9wtpJCuKcUoHPTHMx066ipZK8vE742ZXPc3UMX2g=</dsig:DigestValue>
</hash>
</dependentAssembly>
</dependency>
Expand Down
Binary file modified percentage/bin/Debug/百分比电池图标.pdb
Binary file not shown.
Binary file modified percentage/obj/Debug/percentage.csproj.GenerateResource.cache
Binary file not shown.
2 changes: 1 addition & 1 deletion percentage/obj/Debug/百分比电池图标.application
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
</dsig:Transforms>
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha256" />
<dsig:DigestValue>RswnWJn/IbDfM9cCZnXVeTnIGdjkRcFw2AciWLkT9yY=</dsig:DigestValue>
<dsig:DigestValue>dU1VGpU3B/XGnMs7s0ROwPXQC1+qIyEEQS2Nl+bM6To=</dsig:DigestValue>
</hash>
</dependentAssembly>
</dependency>
Expand Down
Binary file modified percentage/obj/Debug/百分比电池图标.exe
Binary file not shown.
4 changes: 2 additions & 2 deletions percentage/obj/Debug/百分比电池图标.exe.manifest
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@
</dependentAssembly>
</dependency>
<dependency>
<dependentAssembly dependencyType="install" allowDelayedBinding="true" codebase="百分比电池图标.exe" size="94720">
<dependentAssembly dependencyType="install" allowDelayedBinding="true" codebase="百分比电池图标.exe" size="95744">
<assemblyIdentity name="百分比电池图标" version="1.0.0.0" language="neutral" processorArchitecture="msil" />
<hash>
<dsig:Transforms>
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
</dsig:Transforms>
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha256" />
<dsig:DigestValue>MSjlqJ3kqysEPzxDLk1aCFXkoWeh5p9GjnriucqNWCg=</dsig:DigestValue>
<dsig:DigestValue>F1G9wtpJCuKcUoHPTHMx066ipZK8vE742ZXPc3UMX2g=</dsig:DigestValue>
</hash>
</dependentAssembly>
</dependency>
Expand Down
Binary file modified percentage/obj/Debug/百分比电池图标.pdb
Binary file not shown.

0 comments on commit 0ced5fe

Please sign in to comment.