Skip to content

Commit

Permalink
应用字体和背景图设置
Browse files Browse the repository at this point in the history
  • Loading branch information
kagurazakayashi committed Mar 2, 2021
1 parent 24bd244 commit ed983da
Show file tree
Hide file tree
Showing 9 changed files with 445 additions and 128 deletions.
11 changes: 6 additions & 5 deletions MFAScreenLock/MFAScreenLockApp/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
13 changes: 6 additions & 7 deletions MFAScreenLock/MFAScreenLockApp/FormLock.Designer.cs

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

120 changes: 103 additions & 17 deletions MFAScreenLock/MFAScreenLockApp/FormLock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.Drawing.Imaging;
using Google.Authenticator;
using MFAScreenLockApp.Properties;
using System.IO;

namespace MFAScreenLockApp
{
Expand All @@ -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;

Expand All @@ -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 == "")
Expand All @@ -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();
}

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -181,7 +268,6 @@ private void FormLock_FormClosing(object sender, FormClosingEventArgs e)
~FormLock()
{
if (wallPaperBmp != null) wallPaperBmp.Dispose();
if (wallPaperImg != null) wallPaperImg.Dispose();
Dispose();
}
}
Expand Down
16 changes: 8 additions & 8 deletions MFAScreenLock/MFAScreenLockApp/FormLockSub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand Down
Loading

0 comments on commit ed983da

Please sign in to comment.