Skip to content

Commit ed983da

Browse files
应用字体和背景图设置
1 parent 24bd244 commit ed983da

9 files changed

Lines changed: 445 additions & 128 deletions

File tree

MFAScreenLock/MFAScreenLockApp/Form1.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ private void Form1_Load(object sender, EventArgs e)
3939
notifyIcon1.Visible = false;
4040
Application.Exit();
4141
}
42-
wallPaperBmp = SysLink.GetwallPaper();
42+
43+
wallPaperBmp = ShareClass.gWallPaperBmp();
4344
args = Environment.GetCommandLineArgs();
4445
loadConfig();
4546
if (Settings.Default.Timeout >= 60)
@@ -95,7 +96,7 @@ private void locknow()
9596
timer_lock.Enabled = false;
9697
lockallscreen(true, wallPaperBmp);
9798
FormLock formlock = new FormLock();
98-
formlock.wallPaperBmp = wallPaperBmp;
99+
formlock.setBackgroundImage(wallPaperBmp);
99100
formlock.ShowDialog();
100101
formlock.ws = 0;
101102
lockallscreen(false, wallPaperBmp);
@@ -125,7 +126,7 @@ private void lockallscreen(bool islock = true, Bitmap wallPaperBmp = null)
125126
locksub.Left = area.Left;
126127
locksub.Show();
127128
locksub.WindowState = FormWindowState.Maximized;
128-
locksub.wallPaperBmp = wallPaperBmp;
129+
locksub.setBackgroundImage(wallPaperBmp);
129130
formLockSubList.Add(locksub);
130131
}
131132
}
@@ -166,7 +167,7 @@ private void openconfig(Int16 tabindex = 0)
166167
timer_lock.Enabled = false;
167168
FormLock formlock = new FormLock();
168169
formlock.lbl_info.Text = "正在修改绑定设置";
169-
formlock.wallPaperBmp = wallPaperBmp;
170+
formlock.setBackgroundImage(wallPaperBmp);
170171
formlock.ShowDialog();
171172
lockallscreen(false, wallPaperBmp);
172173
if (formlock.ws == 1)
@@ -194,7 +195,7 @@ private void 退出EToolStripMenuItem_Click(object sender, EventArgs e)
194195
timer_lock.Enabled = false;
195196
FormLock formlock = new FormLock();
196197
formlock.lbl_info.Text = "正在尝试退出软件";
197-
formlock.wallPaperBmp = wallPaperBmp;
198+
formlock.setBackgroundImage(wallPaperBmp);
198199
formlock.ShowDialog();
199200
lockallscreen(false, wallPaperBmp);
200201
if (formlock.ws == 1)

MFAScreenLock/MFAScreenLockApp/FormLock.Designer.cs

Lines changed: 6 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

MFAScreenLock/MFAScreenLockApp/FormLock.cs

Lines changed: 103 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using System.Drawing.Imaging;
1111
using Google.Authenticator;
1212
using MFAScreenLockApp.Properties;
13+
using System.IO;
1314

1415
namespace MFAScreenLockApp
1516
{
@@ -24,8 +25,7 @@ public partial class FormLock : Form
2425
public int ws = 0;
2526
private TwoFactorAuthenticator tfa = new TwoFactorAuthenticator();
2627
private HotKeyHandler hook = new HotKeyHandler();
27-
public Bitmap wallPaperBmp;
28-
private Image wallPaperImg;
28+
private Bitmap wallPaperBmp;
2929
private double wallPaperlig = -1;
3030
public bool previewMode = false;
3131

@@ -35,6 +35,16 @@ public FormLock()
3535
//tableLayoutPanel2.BackColor = Color.FromArgb(0, tableLayoutPanel2.BackColor);
3636
}
3737

38+
public void setBackgroundImage(Bitmap wallPaperBmp)
39+
{
40+
this.wallPaperBmp = wallPaperBmp;
41+
if (wallPaperBmp != null)
42+
{
43+
BackgroundImage = ShareClass.autoScaleBitmap(wallPaperBmp, Size);
44+
}
45+
BackgroundImageLayout = ShareClass.imageLayout();
46+
}
47+
3848
private void FormLock_Load(object sender, EventArgs e)
3949
{
4050
if (Settings.Default.AccountSecretKey == "")
@@ -43,24 +53,11 @@ private void FormLock_Load(object sender, EventArgs e)
4353
Close();
4454
return;
4555
}
56+
loadFonts();
4657
hook.HookStart();
4758
Handle1 = this.Handle;
4859
lbl_user.Text = Environment.UserName;
4960
updatedate();
50-
if (wallPaperBmp != null)
51-
{
52-
if (wallPaperlig == -1)
53-
{
54-
wallPaperlig = ImageControl.CalculateAverageLightness(wallPaperBmp);
55-
}
56-
if (wallPaperlig > 0.5)
57-
{
58-
this.ForeColor = Color.Black;
59-
userimage.BackgroundImage = Resources.ic_account_circle_black_48dp;
60-
}
61-
wallPaperImg = ImageControl.scaleBitmap(wallPaperBmp, Size.Width, Size.Height);
62-
BackgroundImage = wallPaperImg;
63-
}
6461
txt_pwdcode.Focus();
6562
}
6663

@@ -144,6 +141,96 @@ private void txt_pwdcode_TextChanged(object sender, EventArgs e)
144141
}
145142
}
146143

144+
private Color gColor()
145+
{
146+
if (wallPaperlig == -1)
147+
{
148+
wallPaperlig = ImageControl.CalculateAverageLightness(wallPaperBmp);
149+
}
150+
if (wallPaperlig > 0.5)
151+
{
152+
return Color.Black;
153+
}
154+
return Color.White;
155+
}
156+
public void loadFonts()
157+
{
158+
if (Settings.Default.FontTime != null)
159+
{
160+
lbl_time.Font = Settings.Default.FontTime;
161+
}
162+
if (Settings.Default.FontDate != null)
163+
{
164+
lbl_date.Font = Settings.Default.FontDate;
165+
}
166+
if (Settings.Default.FontUser != null)
167+
{
168+
lbl_user.Font = Settings.Default.FontUser;
169+
}
170+
if (Settings.Default.FontMenu != null)
171+
{
172+
Font = Settings.Default.FontMenu;
173+
}
174+
if (Settings.Default.FontInfo != null)
175+
{
176+
lbl_info.Font = Settings.Default.FontInfo;
177+
}
178+
if (Settings.Default.FontInput != null)
179+
{
180+
txt_pwdcode.Font = Settings.Default.FontInput;
181+
}
182+
183+
bool nc = !Settings.Default.ColorAuto;
184+
if (nc && Settings.Default.ColorTime != null)
185+
{
186+
lbl_time.ForeColor = Settings.Default.ColorTime;
187+
}
188+
else
189+
{
190+
lbl_time.ForeColor = gColor();
191+
}
192+
if (nc && Settings.Default.ColorDate != null)
193+
{
194+
lbl_date.ForeColor = Settings.Default.ColorDate;
195+
}
196+
else
197+
{
198+
lbl_date.ForeColor = gColor();
199+
}
200+
if (nc && Settings.Default.ColorUser != null)
201+
{
202+
lbl_user.ForeColor = Settings.Default.ColorUser;
203+
}
204+
else
205+
{
206+
lbl_user.ForeColor = gColor();
207+
}
208+
if (nc && Settings.Default.ColorInfo != null)
209+
{
210+
lbl_info.ForeColor = Settings.Default.ColorInfo;
211+
}
212+
else
213+
{
214+
lbl_info.ForeColor = gColor();
215+
}
216+
if (nc && Settings.Default.ColorInput != null)
217+
{
218+
txt_pwdcode.ForeColor = Settings.Default.ColorInput;
219+
}
220+
else
221+
{
222+
txt_pwdcode.ForeColor = gColor();
223+
}
224+
if (nc && Settings.Default.ColorMenu != null)
225+
{
226+
ForeColor = Settings.Default.ColorMenu;
227+
}
228+
else
229+
{
230+
ForeColor = gColor();
231+
}
232+
}
233+
147234
private void timer1_Tick(object sender, EventArgs e)
148235
{
149236
updatedate();
@@ -181,7 +268,6 @@ private void FormLock_FormClosing(object sender, FormClosingEventArgs e)
181268
~FormLock()
182269
{
183270
if (wallPaperBmp != null) wallPaperBmp.Dispose();
184-
if (wallPaperImg != null) wallPaperImg.Dispose();
185271
Dispose();
186272
}
187273
}

MFAScreenLock/MFAScreenLockApp/FormLockSub.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,27 @@ namespace MFAScreenLockApp
1212
{
1313
public partial class FormLockSub : Form
1414
{
15-
public Bitmap wallPaperBmp = null;
16-
private Image wallPaperImg = null;
17-
1815
public FormLockSub()
1916
{
2017
InitializeComponent();
2118
}
2219

23-
private void FormLockSub_Load(object sender, EventArgs e)
20+
public void setBackgroundImage(Bitmap wallPaperBmp)
2421
{
2522
if (wallPaperBmp != null)
2623
{
27-
wallPaperImg = ImageControl.scaleBitmap(wallPaperBmp, Size.Width, Size.Height);
28-
BackgroundImage = wallPaperImg;
24+
BackgroundImage = ShareClass.autoScaleBitmap(wallPaperBmp, Size);
2925
}
26+
BackgroundImageLayout = ShareClass.imageLayout();
27+
}
28+
29+
private void FormLockSub_Load(object sender, EventArgs e)
30+
{
31+
3032
}
3133

3234
~FormLockSub()
3335
{
34-
if (wallPaperBmp != null) wallPaperBmp.Dispose();
35-
if (wallPaperImg != null) wallPaperImg.Dispose();
3636
Dispose();
3737
}
3838
}

0 commit comments

Comments
 (0)