From ed983daf1c98f1e174d1871db166841c1159d6d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A5=9E=E6=A5=BD=E5=9D=82=E9=9B=85=E8=A9=A9?= Date: Tue, 2 Mar 2021 18:00:44 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BA=94=E7=94=A8=E5=AD=97=E4=BD=93=E5=92=8C?= =?UTF-8?q?=E8=83=8C=E6=99=AF=E5=9B=BE=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MFAScreenLock/MFAScreenLockApp/Form1.cs | 11 +- .../MFAScreenLockApp/FormLock.Designer.cs | 13 +- MFAScreenLock/MFAScreenLockApp/FormLock.cs | 120 ++++++++++-- MFAScreenLock/MFAScreenLockApp/FormLockSub.cs | 16 +- .../MFAScreenLockApp/FormUser.Designer.cs | 163 +++++++++------- MFAScreenLock/MFAScreenLockApp/FormUser.cs | 176 ++++++++++++++++-- MFAScreenLock/MFAScreenLockApp/FormUser.resx | 6 + .../MFAScreenLockApp/MFAScreenLockApp.csproj | 1 + MFAScreenLock/MFAScreenLockApp/ShareClass.cs | 67 +++++++ 9 files changed, 445 insertions(+), 128 deletions(-) create mode 100644 MFAScreenLock/MFAScreenLockApp/ShareClass.cs diff --git a/MFAScreenLock/MFAScreenLockApp/Form1.cs b/MFAScreenLock/MFAScreenLockApp/Form1.cs index 53964dd..fc2859d 100644 --- a/MFAScreenLock/MFAScreenLockApp/Form1.cs +++ b/MFAScreenLock/MFAScreenLockApp/Form1.cs @@ -39,7 +39,8 @@ private void Form1_Load(object sender, EventArgs e) notifyIcon1.Visible = false; Application.Exit(); } - wallPaperBmp = SysLink.GetwallPaper(); + + wallPaperBmp = ShareClass.gWallPaperBmp(); args = Environment.GetCommandLineArgs(); loadConfig(); if (Settings.Default.Timeout >= 60) @@ -95,7 +96,7 @@ private void locknow() timer_lock.Enabled = false; lockallscreen(true, wallPaperBmp); FormLock formlock = new FormLock(); - formlock.wallPaperBmp = wallPaperBmp; + formlock.setBackgroundImage(wallPaperBmp); formlock.ShowDialog(); formlock.ws = 0; lockallscreen(false, wallPaperBmp); @@ -125,7 +126,7 @@ private void lockallscreen(bool islock = true, Bitmap wallPaperBmp = null) locksub.Left = area.Left; locksub.Show(); locksub.WindowState = FormWindowState.Maximized; - locksub.wallPaperBmp = wallPaperBmp; + locksub.setBackgroundImage(wallPaperBmp); formLockSubList.Add(locksub); } } @@ -166,7 +167,7 @@ private void openconfig(Int16 tabindex = 0) timer_lock.Enabled = false; FormLock formlock = new FormLock(); formlock.lbl_info.Text = "正在修改绑定设置"; - formlock.wallPaperBmp = wallPaperBmp; + formlock.setBackgroundImage(wallPaperBmp); formlock.ShowDialog(); lockallscreen(false, wallPaperBmp); if (formlock.ws == 1) @@ -194,7 +195,7 @@ private void 退出EToolStripMenuItem_Click(object sender, EventArgs e) timer_lock.Enabled = false; FormLock formlock = new FormLock(); formlock.lbl_info.Text = "正在尝试退出软件"; - formlock.wallPaperBmp = wallPaperBmp; + formlock.setBackgroundImage(wallPaperBmp); formlock.ShowDialog(); lockallscreen(false, wallPaperBmp); if (formlock.ws == 1) diff --git a/MFAScreenLock/MFAScreenLockApp/FormLock.Designer.cs b/MFAScreenLock/MFAScreenLockApp/FormLock.Designer.cs index d5a1157..5d842db 100644 --- a/MFAScreenLock/MFAScreenLockApp/FormLock.Designer.cs +++ b/MFAScreenLock/MFAScreenLockApp/FormLock.Designer.cs @@ -363,7 +363,6 @@ private void InitializeComponent() | System.Windows.Forms.AnchorStyles.Right))); this.label5.BackColor = System.Drawing.Color.Transparent; this.label5.Cursor = System.Windows.Forms.Cursors.Hand; - this.label5.Font = new System.Drawing.Font("微软雅黑", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.label5.Location = new System.Drawing.Point(0, 134); this.label5.Name = "label5"; this.label5.Size = new System.Drawing.Size(294, 42); @@ -404,7 +403,7 @@ private void InitializeComponent() this.lbl_date.Name = "lbl_date"; this.lbl_date.Size = new System.Drawing.Size(441, 35); this.lbl_date.TabIndex = 3; - this.lbl_date.Text = "0"; + this.lbl_date.Text = "---- -- --"; this.lbl_date.TextAlign = System.Drawing.ContentAlignment.BottomLeft; // // lbl_time @@ -417,7 +416,7 @@ private void InitializeComponent() this.lbl_time.Name = "lbl_time"; this.lbl_time.Size = new System.Drawing.Size(459, 140); this.lbl_time.TabIndex = 2; - this.lbl_time.Text = "00:00:00"; + this.lbl_time.Text = "--:--:--"; this.lbl_time.TextAlign = System.Drawing.ContentAlignment.BottomLeft; // // timer1 @@ -465,7 +464,6 @@ private void InitializeComponent() } #endregion - private System.Windows.Forms.Label lbl_user; private System.Windows.Forms.Button button9; private System.Windows.Forms.Button button8; private System.Windows.Forms.Button button7; @@ -480,15 +478,16 @@ private void InitializeComponent() private System.Windows.Forms.Panel panel1; private System.Windows.Forms.Panel userimage; private System.Windows.Forms.Panel panel3; - private System.Windows.Forms.Label lbl_date; - private System.Windows.Forms.Label lbl_time; private System.Windows.Forms.Label label5; private System.Windows.Forms.Button button12; private System.Windows.Forms.Button button11; private System.Windows.Forms.Timer timer1; private System.Windows.Forms.Timer timer2; public System.Windows.Forms.Label lbl_info; - private System.Windows.Forms.TextBox txt_pwdcode; private System.Windows.Forms.TableLayoutPanel softkeyboard; + public System.Windows.Forms.Label lbl_user; + public System.Windows.Forms.Label lbl_date; + public System.Windows.Forms.Label lbl_time; + public System.Windows.Forms.TextBox txt_pwdcode; } } \ No newline at end of file diff --git a/MFAScreenLock/MFAScreenLockApp/FormLock.cs b/MFAScreenLock/MFAScreenLockApp/FormLock.cs index bf9f0a3..efdd02c 100644 --- a/MFAScreenLock/MFAScreenLockApp/FormLock.cs +++ b/MFAScreenLock/MFAScreenLockApp/FormLock.cs @@ -10,6 +10,7 @@ using System.Drawing.Imaging; using Google.Authenticator; using MFAScreenLockApp.Properties; +using System.IO; namespace MFAScreenLockApp { @@ -24,8 +25,7 @@ public partial class FormLock : Form public int ws = 0; private TwoFactorAuthenticator tfa = new TwoFactorAuthenticator(); private HotKeyHandler hook = new HotKeyHandler(); - public Bitmap wallPaperBmp; - private Image wallPaperImg; + private Bitmap wallPaperBmp; private double wallPaperlig = -1; public bool previewMode = false; @@ -35,6 +35,16 @@ public FormLock() //tableLayoutPanel2.BackColor = Color.FromArgb(0, tableLayoutPanel2.BackColor); } + public void setBackgroundImage(Bitmap wallPaperBmp) + { + this.wallPaperBmp = wallPaperBmp; + if (wallPaperBmp != null) + { + BackgroundImage = ShareClass.autoScaleBitmap(wallPaperBmp, Size); + } + BackgroundImageLayout = ShareClass.imageLayout(); + } + private void FormLock_Load(object sender, EventArgs e) { if (Settings.Default.AccountSecretKey == "") @@ -43,24 +53,11 @@ private void FormLock_Load(object sender, EventArgs e) Close(); return; } + loadFonts(); hook.HookStart(); Handle1 = this.Handle; lbl_user.Text = Environment.UserName; updatedate(); - if (wallPaperBmp != null) - { - if (wallPaperlig == -1) - { - wallPaperlig = ImageControl.CalculateAverageLightness(wallPaperBmp); - } - if (wallPaperlig > 0.5) - { - this.ForeColor = Color.Black; - userimage.BackgroundImage = Resources.ic_account_circle_black_48dp; - } - wallPaperImg = ImageControl.scaleBitmap(wallPaperBmp, Size.Width, Size.Height); - BackgroundImage = wallPaperImg; - } txt_pwdcode.Focus(); } @@ -144,6 +141,96 @@ private void txt_pwdcode_TextChanged(object sender, EventArgs e) } } + private Color gColor() + { + if (wallPaperlig == -1) + { + wallPaperlig = ImageControl.CalculateAverageLightness(wallPaperBmp); + } + if (wallPaperlig > 0.5) + { + return Color.Black; + } + return Color.White; + } + public void loadFonts() + { + if (Settings.Default.FontTime != null) + { + lbl_time.Font = Settings.Default.FontTime; + } + if (Settings.Default.FontDate != null) + { + lbl_date.Font = Settings.Default.FontDate; + } + if (Settings.Default.FontUser != null) + { + lbl_user.Font = Settings.Default.FontUser; + } + if (Settings.Default.FontMenu != null) + { + Font = Settings.Default.FontMenu; + } + if (Settings.Default.FontInfo != null) + { + lbl_info.Font = Settings.Default.FontInfo; + } + if (Settings.Default.FontInput != null) + { + txt_pwdcode.Font = Settings.Default.FontInput; + } + + bool nc = !Settings.Default.ColorAuto; + if (nc && Settings.Default.ColorTime != null) + { + lbl_time.ForeColor = Settings.Default.ColorTime; + } + else + { + lbl_time.ForeColor = gColor(); + } + if (nc && Settings.Default.ColorDate != null) + { + lbl_date.ForeColor = Settings.Default.ColorDate; + } + else + { + lbl_date.ForeColor = gColor(); + } + if (nc && Settings.Default.ColorUser != null) + { + lbl_user.ForeColor = Settings.Default.ColorUser; + } + else + { + lbl_user.ForeColor = gColor(); + } + if (nc && Settings.Default.ColorInfo != null) + { + lbl_info.ForeColor = Settings.Default.ColorInfo; + } + else + { + lbl_info.ForeColor = gColor(); + } + if (nc && Settings.Default.ColorInput != null) + { + txt_pwdcode.ForeColor = Settings.Default.ColorInput; + } + else + { + txt_pwdcode.ForeColor = gColor(); + } + if (nc && Settings.Default.ColorMenu != null) + { + ForeColor = Settings.Default.ColorMenu; + } + else + { + ForeColor = gColor(); + } + } + private void timer1_Tick(object sender, EventArgs e) { updatedate(); @@ -181,7 +268,6 @@ private void FormLock_FormClosing(object sender, FormClosingEventArgs e) ~FormLock() { if (wallPaperBmp != null) wallPaperBmp.Dispose(); - if (wallPaperImg != null) wallPaperImg.Dispose(); Dispose(); } } diff --git a/MFAScreenLock/MFAScreenLockApp/FormLockSub.cs b/MFAScreenLock/MFAScreenLockApp/FormLockSub.cs index 825fdd2..7abbafd 100644 --- a/MFAScreenLock/MFAScreenLockApp/FormLockSub.cs +++ b/MFAScreenLock/MFAScreenLockApp/FormLockSub.cs @@ -12,27 +12,27 @@ namespace MFAScreenLockApp { public partial class FormLockSub : Form { - public Bitmap wallPaperBmp = null; - private Image wallPaperImg = null; - public FormLockSub() { InitializeComponent(); } - private void FormLockSub_Load(object sender, EventArgs e) + public void setBackgroundImage(Bitmap wallPaperBmp) { if (wallPaperBmp != null) { - wallPaperImg = ImageControl.scaleBitmap(wallPaperBmp, Size.Width, Size.Height); - BackgroundImage = wallPaperImg; + BackgroundImage = ShareClass.autoScaleBitmap(wallPaperBmp, Size); } + BackgroundImageLayout = ShareClass.imageLayout(); + } + + private void FormLockSub_Load(object sender, EventArgs e) + { + } ~FormLockSub() { - if (wallPaperBmp != null) wallPaperBmp.Dispose(); - if (wallPaperImg != null) wallPaperImg.Dispose(); Dispose(); } } diff --git a/MFAScreenLock/MFAScreenLockApp/FormUser.Designer.cs b/MFAScreenLock/MFAScreenLockApp/FormUser.Designer.cs index f4b3a69..2ea50e4 100644 --- a/MFAScreenLock/MFAScreenLockApp/FormUser.Designer.cs +++ b/MFAScreenLock/MFAScreenLockApp/FormUser.Designer.cs @@ -55,16 +55,17 @@ private void InitializeComponent() this.check_timeoutenable = new System.Windows.Forms.CheckBox(); this.check_loginstart = new System.Windows.Forms.CheckBox(); this.tabPage3 = new System.Windows.Forms.TabPage(); + this.groupBox5 = new System.Windows.Forms.GroupBox(); + this.label3 = new System.Windows.Forms.Label(); + this.combo_scale = new System.Windows.Forms.ComboBox(); + this.combo_background = new System.Windows.Forms.ComboBox(); this.groupBox4 = new System.Windows.Forms.GroupBox(); - this.checkBox1 = new System.Windows.Forms.CheckBox(); + this.check_autocolor = new System.Windows.Forms.CheckBox(); this.btn_font = new System.Windows.Forms.Button(); this.combo_font = new System.Windows.Forms.ComboBox(); this.timer1 = new System.Windows.Forms.Timer(this.components); this.fontDialog1 = new System.Windows.Forms.FontDialog(); - this.groupBox5 = new System.Windows.Forms.GroupBox(); - this.comboBox1 = new System.Windows.Forms.ComboBox(); - this.comboBox2 = new System.Windows.Forms.ComboBox(); - this.label3 = new System.Windows.Forms.Label(); + this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog(); this.groupBox2.SuspendLayout(); this.groupBox1.SuspendLayout(); this.tabControl1.SuspendLayout(); @@ -73,8 +74,8 @@ private void InitializeComponent() this.groupBox3.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.num_timeout)).BeginInit(); this.tabPage3.SuspendLayout(); - this.groupBox4.SuspendLayout(); this.groupBox5.SuspendLayout(); + this.groupBox4.SuspendLayout(); this.SuspendLayout(); // // label1 @@ -389,9 +390,68 @@ private void InitializeComponent() this.tabPage3.Text = "个性化"; this.tabPage3.UseVisualStyleBackColor = true; // + // groupBox5 + // + this.groupBox5.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.groupBox5.Controls.Add(this.label3); + this.groupBox5.Controls.Add(this.combo_scale); + this.groupBox5.Controls.Add(this.combo_background); + this.groupBox5.Location = new System.Drawing.Point(6, 104); + this.groupBox5.Name = "groupBox5"; + this.groupBox5.Size = new System.Drawing.Size(580, 95); + this.groupBox5.TabIndex = 1; + this.groupBox5.TabStop = false; + this.groupBox5.Text = "背景图设置"; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(6, 62); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(51, 20); + this.label3.TabIndex = 2; + this.label3.Text = "布局:"; + // + // combo_scale + // + this.combo_scale.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.combo_scale.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.combo_scale.FormattingEnabled = true; + this.combo_scale.Items.AddRange(new object[] { + "禁用", + "标准", + "居中", + "拉伸", + "缩放", + "填充"}); + this.combo_scale.Location = new System.Drawing.Point(113, 59); + this.combo_scale.Name = "combo_scale"; + this.combo_scale.Size = new System.Drawing.Size(461, 28); + this.combo_scale.TabIndex = 1; + this.combo_scale.SelectedIndexChanged += new System.EventHandler(this.combo_scale_SelectedIndexChanged); + // + // combo_background + // + this.combo_background.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.combo_background.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.combo_background.FormattingEnabled = true; + this.combo_background.Items.AddRange(new object[] { + "使用我的主屏桌面壁纸", + "选择一个文件..."}); + this.combo_background.Location = new System.Drawing.Point(6, 25); + this.combo_background.Name = "combo_background"; + this.combo_background.Size = new System.Drawing.Size(568, 28); + this.combo_background.TabIndex = 0; + this.combo_background.SelectedIndexChanged += new System.EventHandler(this.combo_background_SelectedIndexChanged); + // // groupBox4 // - this.groupBox4.Controls.Add(this.checkBox1); + this.groupBox4.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.groupBox4.Controls.Add(this.check_autocolor); this.groupBox4.Controls.Add(this.btn_font); this.groupBox4.Controls.Add(this.combo_font); this.groupBox4.Location = new System.Drawing.Point(6, 6); @@ -401,22 +461,24 @@ private void InitializeComponent() this.groupBox4.TabStop = false; this.groupBox4.Text = "字体设置"; // - // checkBox1 + // check_autocolor // - this.checkBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + this.check_autocolor.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); - this.checkBox1.Checked = true; - this.checkBox1.CheckState = System.Windows.Forms.CheckState.Checked; - this.checkBox1.Location = new System.Drawing.Point(6, 59); - this.checkBox1.Name = "checkBox1"; - this.checkBox1.Size = new System.Drawing.Size(421, 27); - this.checkBox1.TabIndex = 2; - this.checkBox1.Text = "根据我的背景图自动决定所有字体是黑色还是白色"; - this.checkBox1.UseVisualStyleBackColor = true; + this.check_autocolor.Checked = true; + this.check_autocolor.CheckState = System.Windows.Forms.CheckState.Checked; + this.check_autocolor.Location = new System.Drawing.Point(6, 59); + this.check_autocolor.Name = "check_autocolor"; + this.check_autocolor.Size = new System.Drawing.Size(421, 27); + this.check_autocolor.TabIndex = 2; + this.check_autocolor.Text = "根据我的背景图自动决定所有字体是黑色还是白色"; + this.check_autocolor.UseVisualStyleBackColor = true; + this.check_autocolor.CheckedChanged += new System.EventHandler(this.check_autocolor_CheckedChanged); // // btn_font // this.btn_font.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.btn_font.Enabled = false; this.btn_font.Location = new System.Drawing.Point(434, 57); this.btn_font.Name = "btn_font"; this.btn_font.Size = new System.Drawing.Size(140, 28); @@ -435,66 +497,22 @@ private void InitializeComponent() this.combo_font.Name = "combo_font"; this.combo_font.Size = new System.Drawing.Size(568, 28); this.combo_font.TabIndex = 0; + this.combo_font.SelectedIndexChanged += new System.EventHandler(this.combo_font_SelectedIndexChanged); // // timer1 // this.timer1.Enabled = true; this.timer1.Tick += new System.EventHandler(this.timer1_Tick); // - // groupBox5 + // fontDialog1 // - this.groupBox5.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.groupBox5.Controls.Add(this.label3); - this.groupBox5.Controls.Add(this.comboBox2); - this.groupBox5.Controls.Add(this.comboBox1); - this.groupBox5.Location = new System.Drawing.Point(6, 104); - this.groupBox5.Name = "groupBox5"; - this.groupBox5.Size = new System.Drawing.Size(580, 95); - this.groupBox5.TabIndex = 1; - this.groupBox5.TabStop = false; - this.groupBox5.Text = "背景图设置"; + this.fontDialog1.ShowColor = true; // - // comboBox1 + // openFileDialog1 // - this.comboBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; - this.comboBox1.FormattingEnabled = true; - this.comboBox1.Items.AddRange(new object[] { - "使用我的主屏桌面壁纸", - "选择一个文件..."}); - this.comboBox1.Location = new System.Drawing.Point(6, 25); - this.comboBox1.Name = "comboBox1"; - this.comboBox1.Size = new System.Drawing.Size(568, 28); - this.comboBox1.TabIndex = 0; - // - // comboBox2 - // - this.comboBox2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.comboBox2.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; - this.comboBox2.FormattingEnabled = true; - this.comboBox2.Items.AddRange(new object[] { - "禁用", - "标准", - "居中", - "拉伸", - "缩放", - "填充"}); - this.comboBox2.Location = new System.Drawing.Point(113, 59); - this.comboBox2.Name = "comboBox2"; - this.comboBox2.Size = new System.Drawing.Size(461, 28); - this.comboBox2.TabIndex = 1; - // - // label3 - // - this.label3.AutoSize = true; - this.label3.Location = new System.Drawing.Point(6, 62); - this.label3.Name = "label3"; - this.label3.Size = new System.Drawing.Size(51, 20); - this.label3.TabIndex = 2; - this.label3.Text = "布局:"; + this.openFileDialog1.FileName = "openFileDialog1"; + this.openFileDialog1.Filter = resources.GetString("openFileDialog1.Filter"); + this.openFileDialog1.Title = "选择一个图像文件作为背景图"; // // FormUser // @@ -523,9 +541,9 @@ private void InitializeComponent() this.groupBox3.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.num_timeout)).EndInit(); this.tabPage3.ResumeLayout(false); - this.groupBox4.ResumeLayout(false); this.groupBox5.ResumeLayout(false); this.groupBox5.PerformLayout(); + this.groupBox4.ResumeLayout(false); this.ResumeLayout(false); } @@ -558,13 +576,14 @@ private void InitializeComponent() private System.Windows.Forms.TabPage tabPage3; private System.Windows.Forms.LinkLabel btn_rmsetting; private System.Windows.Forms.GroupBox groupBox4; - private System.Windows.Forms.CheckBox checkBox1; + private System.Windows.Forms.CheckBox check_autocolor; private System.Windows.Forms.Button btn_font; private System.Windows.Forms.ComboBox combo_font; private System.Windows.Forms.FontDialog fontDialog1; private System.Windows.Forms.GroupBox groupBox5; - private System.Windows.Forms.ComboBox comboBox1; + private System.Windows.Forms.ComboBox combo_background; private System.Windows.Forms.Label label3; - private System.Windows.Forms.ComboBox comboBox2; + private System.Windows.Forms.ComboBox combo_scale; + private System.Windows.Forms.OpenFileDialog openFileDialog1; } } \ No newline at end of file diff --git a/MFAScreenLock/MFAScreenLockApp/FormUser.cs b/MFAScreenLock/MFAScreenLockApp/FormUser.cs index 0b17cc4..c29f5b3 100644 --- a/MFAScreenLock/MFAScreenLockApp/FormUser.cs +++ b/MFAScreenLock/MFAScreenLockApp/FormUser.cs @@ -17,7 +17,8 @@ public partial class FormUser : Form { private FormLock formlock = null; private Font[] fontSet = new Font[6]; - + private int selectFontItem = -1; + private bool loadOK = false; public int ws = 0; public FormUser() @@ -34,11 +35,26 @@ private void loaddata() { isbind(); check_loginstart.Checked = Settings.Default.LoginStart; + check_autocolor.Checked = Settings.Default.ColorAuto; + combo_scale.SelectedIndex = Settings.Default.Scale; + if (Settings.Default.Background.Length > 0) + { + combo_background.Items.Clear(); + combo_background.Items.Add("使用我的主屏桌面壁纸"); + combo_background.Items.Add(Settings.Default.Background); + combo_background.Items.Add("选择一个文件..."); + combo_background.SelectedIndex = 1; + } + else + { + combo_background.SelectedIndex = 0; + } int timeouts = Settings.Default.Timeout; num_timeout.Value = timeouts / 60; prog_timeout.Value = 0; prog_timeout.Maximum = timeouts * 1000; check_timeoutenable.Checked = Settings.Default.TimeoutEnable; + loadOK = true; } private bool isbind() @@ -195,10 +211,11 @@ private void showPreview() formlock = new FormLock(); formlock.Text = "锁屏效果预览"; formlock.lbl_info.Text = formlock.Text; - formlock.wallPaperBmp = ShareClass.gWallPaperBmp(); + formlock.setBackgroundImage(ShareClass.gWallPaperBmp()); formlock.previewMode = true; formlock.FormBorderStyle = FormBorderStyle.Fixed3D; formlock.ControlBox = true; + formlock.MaximizeBox = true; formlock.TopMost = false; TopMost = true; formlock.Show(); @@ -216,6 +233,7 @@ private void tabControl1_SelectedIndexChanged(object sender, EventArgs e) { if (combo_font.Items.Count > 0) { + btn_font.Enabled = false; combo_font.Items.Clear(); } TopMost = false; @@ -242,32 +260,152 @@ private void loadFonts() private void btn_font_Click(object sender, EventArgs e) { - // combo_font - fontDialog1.ShowDialog(); - - if (Settings.Default.FontTime != null) + switch (selectFontItem) { - formlock.lbl_time.Font.ToString(); + case 0: + fontDialog1.Font = formlock.lbl_time.Font; + fontDialog1.Color = formlock.lbl_time.ForeColor; + break; + case 1: + fontDialog1.Font = formlock.lbl_date.Font; + fontDialog1.Color = formlock.lbl_date.ForeColor; + break; + case 2: + fontDialog1.Font = formlock.lbl_user.Font; + fontDialog1.Color = formlock.lbl_user.ForeColor; + break; + case 3: + fontDialog1.Font = formlock.lbl_info.Font; + fontDialog1.Color = formlock.lbl_info.ForeColor; + break; + case 4: + fontDialog1.Font = formlock.txt_pwdcode.Font; + fontDialog1.Color = formlock.txt_pwdcode.ForeColor; + break; + case 5: + fontDialog1.Font = formlock.Font; + fontDialog1.Color = formlock.ForeColor; + break; + default: + break; } - if (Settings.Default.FontDate != null) + if (fontDialog1.ShowDialog() != DialogResult.Cancel) { - formlock.lbl_date.Font.ToString(); - } - if (Settings.Default.FontUser != null) - { - formlock.lbl_user.Font.ToString(); + switch (selectFontItem) + { + case 0: + Settings.Default.FontTime = fontDialog1.Font; + formlock.lbl_time.Font = fontDialog1.Font; + if (!check_autocolor.Checked) + { + Settings.Default.ColorTime = fontDialog1.Color; + formlock.lbl_time.ForeColor = fontDialog1.Color; + } + break; + case 1: + Settings.Default.FontDate = fontDialog1.Font; + formlock.lbl_date.Font = fontDialog1.Font; + if (!check_autocolor.Checked) + { + Settings.Default.ColorDate = fontDialog1.Color; + formlock.lbl_date.ForeColor = fontDialog1.Color; + } + break; + case 2: + Settings.Default.FontUser = fontDialog1.Font; + formlock.lbl_user.Font = fontDialog1.Font; + if (!check_autocolor.Checked) + { + Settings.Default.ColorUser = fontDialog1.Color; + formlock.lbl_user.ForeColor = fontDialog1.Color; + } + break; + case 3: + Settings.Default.FontInfo = fontDialog1.Font; + formlock.lbl_info.Font = fontDialog1.Font; + if (!check_autocolor.Checked) + { + Settings.Default.ColorInfo = fontDialog1.Color; + formlock.lbl_info.ForeColor = fontDialog1.Color; + } + break; + case 4: + Settings.Default.FontInput = fontDialog1.Font; + formlock.txt_pwdcode.Font = fontDialog1.Font; + if (!check_autocolor.Checked) + { + Settings.Default.ColorInput = fontDialog1.Color; + formlock.txt_pwdcode.ForeColor = fontDialog1.Color; + } + break; + case 5: + Settings.Default.FontMenu = fontDialog1.Font; + formlock.Font = fontDialog1.Font; + if (!check_autocolor.Checked) + { + Settings.Default.ColorMenu = fontDialog1.Color; + formlock.ForeColor = fontDialog1.Color; + } + break; + default: + break; + } } - if (Settings.Default.FontMenu != null) + } + + private void combo_font_SelectedIndexChanged(object sender, EventArgs e) + { + btn_font.Enabled = true; + selectFontItem = combo_font.SelectedIndex; + } + + private void check_autocolor_CheckedChanged(object sender, EventArgs e) + { + Settings.Default.ColorAuto = check_autocolor.Checked; + if (check_autocolor.Checked) { - formlock.Font.ToString(); + formlock.loadFonts(); } - if (Settings.Default.FontInfo != null) + } + + private void combo_background_SelectedIndexChanged(object sender, EventArgs e) + { + if (loadOK) { - formlock.lbl_info.Font.ToString(); + if (combo_background.SelectedIndex == 0) + { + loadOK = false; + Settings.Default.Background = ""; + combo_background.Items.Clear(); + combo_background.Items.Add("使用我的主屏桌面壁纸"); + combo_background.Items.Add("选择一个文件..."); + combo_background.SelectedIndex = 0; + loadOK = true; + } + else + { + if (openFileDialog1.ShowDialog() != DialogResult.Cancel) + { + Settings.Default.Background = openFileDialog1.FileName; + loadOK = false; + combo_background.Items.Clear(); + combo_background.Items.Add("使用我的主屏桌面壁纸"); + combo_background.Items.Add(openFileDialog1.FileName); + combo_background.Items.Add("选择一个文件..."); + combo_background.SelectedIndex = 0; + loadOK = true; + } + } + formlock.setBackgroundImage(ShareClass.gWallPaperBmp()); } - if (Settings.Default.FontInput != null) + } + + private void combo_scale_SelectedIndexChanged(object sender, EventArgs e) + { + if (loadOK) { - formlock.txt_pwdcode.Font.ToString(); + Settings.Default.Scale = combo_scale.SelectedIndex; + formlock.setBackgroundImage(ShareClass.gWallPaperBmp()); } } } diff --git a/MFAScreenLock/MFAScreenLockApp/FormUser.resx b/MFAScreenLock/MFAScreenLockApp/FormUser.resx index 458346e..583d16b 100644 --- a/MFAScreenLock/MFAScreenLockApp/FormUser.resx +++ b/MFAScreenLock/MFAScreenLockApp/FormUser.resx @@ -123,6 +123,12 @@ 110, 17 + + 238, 17 + + + 所有图片文件 (*.bmp;*.ico;*.gif;*.jpeg;*.jpg;*.png;*.tif;*.tiff)|*.bmp;*.ico;*.gif;*.jpeg;*.jpg;*.png;*.tif;*.tiff|Windows 位图 (*.bmp)|*.bmp|JPEG 联合图像专家组 (*.jpg;*.jpeg)|*.jpg;*.jpeg|PNG 可移植网络图像 (*.png)|*.png|TIFF 格式 (*.tif)|*.tif;*.tiff|所有文件|*.* + diff --git a/MFAScreenLock/MFAScreenLockApp/MFAScreenLockApp.csproj b/MFAScreenLock/MFAScreenLockApp/MFAScreenLockApp.csproj index 1afaead..c0ef348 100644 --- a/MFAScreenLock/MFAScreenLockApp/MFAScreenLockApp.csproj +++ b/MFAScreenLock/MFAScreenLockApp/MFAScreenLockApp.csproj @@ -151,6 +151,7 @@ + Form1.cs diff --git a/MFAScreenLock/MFAScreenLockApp/ShareClass.cs b/MFAScreenLock/MFAScreenLockApp/ShareClass.cs new file mode 100644 index 0000000..3b4419b --- /dev/null +++ b/MFAScreenLock/MFAScreenLockApp/ShareClass.cs @@ -0,0 +1,67 @@ +using MFAScreenLockApp.Properties; +using System; +using System.Collections.Generic; +using System.Drawing; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace MFAScreenLockApp +{ + class ShareClass + { + public static Bitmap gWallPaperBmp() + { + //string path = AppDomain.CurrentDomain.BaseDirectory + Settings.Default.Background; + if (Settings.Default.Background.Length > 0) + { + if (File.Exists(Settings.Default.Background)) + { + FileStream fileStream = File.OpenRead(Settings.Default.Background); + Int32 filelength = 0; + filelength = (int)fileStream.Length; + Byte[] image = new Byte[filelength]; + fileStream.Read(image, 0, filelength); + Image result = Image.FromStream(fileStream); + fileStream.Close(); + return new Bitmap(result); + } + } + return SysLink.GetwallPaper(); + } + + public static Image autoScaleBitmap(Bitmap wallPaperBmp, Size size) + { + if (Settings.Default.Scale == 0) + { + return null; + } + else if (Settings.Default.Scale == 5) + { + return ImageControl.scaleBitmap(wallPaperBmp, size.Width, size.Height); + } + return wallPaperBmp; + } + + public static ImageLayout imageLayout() + { + switch (Settings.Default.Scale) + { + case 0: + return ImageLayout.None; + case 1: + return ImageLayout.None; + case 2: + return ImageLayout.Center; + case 3: + return ImageLayout.Stretch; + case 4: + return ImageLayout.Zoom; + default: + return ImageLayout.Stretch; + } + } + } +}