123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266 |
- using BatteryIndicator.Model;
- using BatteryIndicator.Views;
- using Microsoft.Win32;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace BatteryIndicator.UI
- {
- public partial class SettingForm : BaseForm
- {
- public SettingForm()
- {
- PTConfig cfg = new PTConfig();
- cfg.Load();
- string fontsize = cfg.FontSize;
- string xoffset = cfg.XOffset;
- string yoffset = cfg.YOffset;
- string normalColor = cfg.NormalColor;
- string chargingColor = cfg.ChargingColor;
- string lowColor = cfg.LowColor;
- InitializeComponent(); //绘制控件
- textBox1.Text = fontsize;
- textBox3.Text = xoffset;
- textBox4.Text = yoffset;
- pictureBox1.BackColor = (Color)new ColorConverter().ConvertFromString(normalColor); // 从字符串获取颜色
- pictureBox2.BackColor = (Color)new ColorConverter().ConvertFromString(chargingColor);
- pictureBox3.BackColor = (Color)new ColorConverter().ConvertFromString(lowColor);
- // 解决textbox1自动聚焦的问题
- textBox2.Visible = false;
- textBox2.Enabled = false;
- ActiveControl = textBox2;
- }
- private void label1_Click(object sender, EventArgs e)
- {
- }
- private void label2_Click(object sender, EventArgs e)
- {
- }
- private void label4_Click(object sender, EventArgs e)
- {
- }
- private void label3_Click(object sender, EventArgs e)
- {
- }
- private void textBox1_TextChanged(object sender, EventArgs e)
- {
- try
- {
- TrayIcon.iconFontSize = Convert.ToInt32(textBox1.Text);
- // 将设置的字号保存到注册表中
- //RegistryKey hklm = Registry.CurrentUser;
- //RegistryKey lgn = hklm.OpenSubKey(@"Software", true).CreateSubKey("BatteryIcon");
- //lgn.SetValue("fontsize", textBox1.Text, RegistryValueKind.String);
- PTConfig cfg = new PTConfig();
- cfg.Load();
- cfg.FontSize = textBox1.Text;
- cfg.Update();
- }
- catch
- {
- // do nothing
- }
- }
- private void textBox3_TextChanged(object sender, EventArgs e)
- {
- try
- {
- TrayIcon.xoffset = Convert.ToInt32(textBox3.Text);
- //RegistryKey hklm = Registry.CurrentUser;
- //RegistryKey lgn = hklm.OpenSubKey(@"Software", true).CreateSubKey("BatteryIcon");
- //lgn.SetValue("xoffset", textBox3.Text, RegistryValueKind.String);
- PTConfig cfg = new PTConfig();
- cfg.Load();
- cfg.XOffset = textBox3.Text;
- cfg.Update();
- }
- catch
- {
- // do nothing
- }
- }
- private void textBox4_TextChanged(object sender, EventArgs e)
- {
- try
- {
- TrayIcon.yoffset = Convert.ToInt32(textBox4.Text);
- //RegistryKey hklm = Registry.CurrentUser;
- //RegistryKey lgn = hklm.OpenSubKey(@"Software", true).CreateSubKey("BatteryIcon");
- //lgn.SetValue("yoffset", textBox4.Text, RegistryValueKind.String);
- PTConfig cfg = new PTConfig();
- cfg.Load();
- cfg.YOffset = textBox4.Text;
- cfg.Update();
- }
- catch
- {
- // do nothing
- }
- }
- private void pictureBox1_Click_1(object sender, EventArgs e)
- {
- ColorDialog loColorForm = new ColorDialog();
- if (loColorForm.ShowDialog() == DialogResult.OK)
- {
- pictureBox1.BackColor = loColorForm.Color;
- TrayIcon.normalColor = loColorForm.Color;
- // 将设置的颜色保存到注册表中
- //RegistryKey hklm = Registry.CurrentUser;
- //RegistryKey lgn = hklm.OpenSubKey(@"Software", true).CreateSubKey("BatteryIcon");
- //lgn.SetValue("normalColor", new ColorConverter().ConvertToString(TrayIcon.normalColor), RegistryValueKind.String);
- PTConfig cfg = new PTConfig();
- cfg.Load();
- cfg.NormalColor = new ColorConverter().ConvertToString(TrayIcon.normalColor);
- cfg.Update();
- }
- }
- private void pictureBox2_Click(object sender, EventArgs e)
- {
- ColorDialog loColorForm = new ColorDialog();
- if (loColorForm.ShowDialog() == DialogResult.OK)
- {
- pictureBox2.BackColor = loColorForm.Color;
- TrayIcon.chargingColor = loColorForm.Color;
- // 将设置的颜色保存到注册表中
- //RegistryKey hklm = Registry.CurrentUser;
- //RegistryKey lgn = hklm.OpenSubKey(@"Software", true).CreateSubKey("BatteryIcon");
- //lgn.SetValue("chargingColor", new ColorConverter().ConvertToString(TrayIcon.chargingColor), RegistryValueKind.String);
- PTConfig cfg = new PTConfig();
- cfg.Load();
- cfg.ChargingColor = new ColorConverter().ConvertToString(TrayIcon.chargingColor);
- cfg.Update();
- }
- }
- private void pictureBox3_Click(object sender, EventArgs e)
- {
- ColorDialog loColorForm = new ColorDialog();
- if (loColorForm.ShowDialog() == DialogResult.OK)
- {
- pictureBox3.BackColor = loColorForm.Color;
- TrayIcon.lowColor = loColorForm.Color; // 更新颜色
- // 将设置的颜色保存到注册表中
- //RegistryKey hklm = Registry.CurrentUser;
- //RegistryKey lgn = hklm.OpenSubKey(@"Software", true).CreateSubKey("BatteryIcon");
- //lgn.SetValue("lowColor", new ColorConverter().ConvertToString(TrayIcon.lowColor), RegistryValueKind.String);
- PTConfig cfg = new PTConfig();
- cfg.Load();
- cfg.LowColor = new ColorConverter().ConvertToString(TrayIcon.lowColor);
- cfg.Update();
- }
- }
- // 限制文本框只能输入数字
- private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
- {
- if (!Char.IsNumber(e.KeyChar) && e.KeyChar != (char)8)
- {
- e.Handled = true;
- }
- }
- private void textBox3_KeyPress(object sender, KeyPressEventArgs e)
- {
- if (!Char.IsNumber(e.KeyChar) && e.KeyChar != (char)8 && e.KeyChar != '-')
- {
- e.Handled = true;
- }
- }
- private void textBox4_KeyPress(object sender, KeyPressEventArgs e)
- {
- if (!Char.IsNumber(e.KeyChar) && e.KeyChar != (char)8 && e.KeyChar != '-')
- {
- e.Handled = true;
- }
- }
- private void pictureBox4_Click(object sender, EventArgs e)
- {
- }
- private void label7_Click(object sender, EventArgs e)
- {
- RegistryKey key = Registry.ClassesRoot.OpenSubKey(@"http\shell\open\command\");
- string s = key.GetValue("").ToString();
- Regex reg = new Regex("\"([^\"]+)\"");
- MatchCollection matchs = reg.Matches(s);
- string filename = "";
- 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 checkBox1_CheckedChanged(object sender, EventArgs e)
- {
- //RegistryKey hklm = Registry.CurrentUser;
- //RegistryKey lgn = hklm.OpenSubKey(@"Software\BatteryIcon", true);
- PTConfig cfg = new PTConfig();
- cfg.Load();
- if (checkBox1.Checked == true)
- {
- TrayIcon.autoHide = "true";
- //lgn.SetValue("autoHide", "true", RegistryValueKind.String);
- cfg.AutoHide = "true";
- }
- else
- {
- TrayIcon.autoHide = "false";
- //lgn.SetValue("autoHide", "false", RegistryValueKind.String);
- cfg.AutoHide = "false";
- }
- cfg.Update();
- }
-
- }
- }
|