1010using System . Drawing . Imaging ;
1111using Google . Authenticator ;
1212using MFAScreenLockApp . Properties ;
13+ using System . IO ;
1314
1415namespace 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 }
0 commit comments