11
11
using System . Windows . Media . Animation ;
12
12
using SoftwareHelper . Helpers ;
13
13
using SoftwareHelper . ViewModels ;
14
+ using WPFDevelopers . Controls ;
14
15
15
16
namespace SoftwareHelper . Views
16
17
{
@@ -19,12 +20,12 @@ namespace SoftwareHelper.Views
19
20
/// </summary>
20
21
public partial class EmbedDeasktopView : Window
21
22
{
22
- private bool inDrag ;
23
- private readonly Rect desktopWorkingArea ;
24
- private Point anchorPoint ;
25
23
private readonly KeyboardHook _hook ;
24
+ private readonly Rect desktopWorkingArea ;
26
25
private readonly List < Key > keys = new List < Key > ( ) ;
27
- private MainVM mainVM ;
26
+ private Point anchorPoint ;
27
+ private bool inDrag ;
28
+ private readonly MainVM mainVM ;
28
29
29
30
public EmbedDeasktopView ( )
30
31
{
@@ -51,7 +52,7 @@ private void OnHookKeyDown(object sender, HookEventArgs e)
51
52
SetKeyDown ( e . Key ) ;
52
53
if ( IsKeyDown ( Key . PrintScreen ) )
53
54
{
54
- var screenCut = new WPFDevelopers . Controls . ScreenCut ( ) ;
55
+ var screenCut = new ScreenCut ( ) ;
55
56
screenCut . ShowDialog ( ) ;
56
57
}
57
58
else
@@ -152,7 +153,33 @@ private void MenuItem_Click(object sender, RoutedEventArgs e)
152
153
myNotifyIcon . Dispose ( ) ;
153
154
Environment . Exit ( 0 ) ;
154
155
}
156
+
157
+ public void ExitEmbedded ( )
158
+ {
159
+ if ( ToggleButtonMini . IsChecked == true )
160
+ Width = 30 ;
161
+ else
162
+ Width = 120 ;
163
+ Height = desktopWorkingArea . Height / 2 ;
164
+ Left = desktopWorkingArea . Width - Width ;
165
+ Top = desktopWorkingArea . Height / 2 - Height / 2 ;
166
+ }
167
+
168
+ public void OepnEmbedded ( )
169
+ {
170
+ if ( mainVM . IsEmbedded ) return ;
171
+ }
172
+
173
+ private void myNotifyIcon_TrayLeftMouseUp ( object sender , RoutedEventArgs e )
174
+ {
175
+ if ( mainVM . IsEmbedded ) return ;
176
+ Show ( ) ;
177
+ Activate ( ) ;
178
+ Focus ( ) ;
179
+ }
180
+
155
181
#region 移动窗体
182
+
156
183
protected override void OnMouseLeftButtonDown ( MouseButtonEventArgs e )
157
184
{
158
185
anchorPoint = e . GetPosition ( this ) ;
@@ -165,16 +192,9 @@ protected override void OnMouseMove(MouseEventArgs e)
165
192
{
166
193
try
167
194
{
168
- if ( ! inDrag ) return ;
195
+ if ( ! inDrag && e . LeftButton != MouseButtonState . Pressed ) return ;
169
196
var currentPoint = e . GetPosition ( this ) ;
170
- var y = this . Top + currentPoint . Y - anchorPoint . Y ;
171
- Win32Api . RECT rect ;
172
- Win32Api . GetWindowRect ( new WindowInteropHelper ( this ) . Handle , out rect ) ;
173
- var w = rect . right - rect . left ;
174
- var h = rect . bottom - rect . top ;
175
- int x = Convert . ToInt32 ( PrimaryScreen . DESKTOP . Width - w ) ;
176
- Win32Api . MoveWindow ( new WindowInteropHelper ( this ) . Handle , x , ( int ) y , w , h , 1 ) ;
177
-
197
+ Top = Top + ( currentPoint . Y - anchorPoint . Y ) ;
178
198
}
179
199
catch ( Exception ex )
180
200
{
@@ -191,31 +211,18 @@ protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e)
191
211
e . Handled = true ;
192
212
}
193
213
}
214
+
194
215
#endregion
195
- public void ExitEmbedded ( )
196
- {
197
- if ( ToggleButtonMini . IsChecked == true )
198
- Width = 30 ;
199
- else
200
- Width = 120 ;
201
- Height = desktopWorkingArea . Height / 2 ;
202
- Left = desktopWorkingArea . Width - Width ;
203
- Top = desktopWorkingArea . Height / 2 - ( Height / 2 ) ;
204
- }
205
- public void OepnEmbedded ( )
206
- {
207
- if ( mainVM . IsEmbedded ) return ;
208
216
209
- }
210
217
#region 窗体动画
218
+
211
219
private void ToggleButtonMini_Checked ( object sender , RoutedEventArgs e )
212
220
{
213
-
214
221
try
215
222
{
216
- EasingFunctionBase easeFunction = new CubicEase ( )
223
+ EasingFunctionBase easeFunction = new CubicEase
217
224
{
218
- EasingMode = EasingMode . EaseOut ,
225
+ EasingMode = EasingMode . EaseOut
219
226
} ;
220
227
221
228
var heightAnimation = new DoubleAnimation
@@ -224,23 +231,20 @@ private void ToggleButtonMini_Checked(object sender, RoutedEventArgs e)
224
231
From = desktopWorkingArea . Height / 2 ,
225
232
To = 60 ,
226
233
Duration = new Duration ( TimeSpan . FromSeconds ( 0.5 ) ) ,
227
- EasingFunction = easeFunction ,
228
- } ;
229
- heightAnimation . Completed += delegate
230
- {
231
- BeginAnimation ( HeightProperty , null ) ;
234
+ EasingFunction = easeFunction
232
235
} ;
236
+ heightAnimation . Completed += delegate { BeginAnimation ( HeightProperty , null ) ; } ;
233
237
var widthAnimation = new DoubleAnimation
234
238
{
235
239
Name = "widthMini" ,
236
240
From = 120 ,
237
241
To = 30 ,
238
242
Duration = new Duration ( TimeSpan . FromSeconds ( 0.51 ) ) ,
239
- EasingFunction = easeFunction ,
243
+ EasingFunction = easeFunction
240
244
} ;
241
245
widthAnimation . Completed += delegate
242
246
{
243
- Left = desktopWorkingArea . Width - this . Width ;
247
+ Left = desktopWorkingArea . Width - Width ;
244
248
BeginAnimation ( WidthProperty , null ) ;
245
249
} ;
246
250
BeginAnimation ( HeightProperty , heightAnimation ) ;
@@ -253,26 +257,24 @@ private void ToggleButtonMini_Checked(object sender, RoutedEventArgs e)
253
257
}
254
258
255
259
256
-
257
260
private void UnToggleButtonMini_Checked ( object sender , RoutedEventArgs e )
258
261
{
259
-
260
262
try
261
263
{
262
- var easeFunction = new CubicEase ( )
264
+ var easeFunction = new CubicEase
263
265
{
264
- EasingMode = EasingMode . EaseIn ,
266
+ EasingMode = EasingMode . EaseIn
265
267
} ;
266
268
var widthAnimation = new DoubleAnimation
267
269
{
268
270
From = 30 ,
269
271
To = 120 ,
270
272
Duration = new Duration ( TimeSpan . FromSeconds ( 0.01 ) ) ,
271
- EasingFunction = easeFunction ,
273
+ EasingFunction = easeFunction
272
274
} ;
273
275
widthAnimation . Completed += delegate
274
276
{
275
- Left = desktopWorkingArea . Width - this . Width ;
277
+ Left = desktopWorkingArea . Width - Width ;
276
278
BeginAnimation ( WidthProperty , null ) ;
277
279
} ;
278
280
@@ -281,31 +283,18 @@ private void UnToggleButtonMini_Checked(object sender, RoutedEventArgs e)
281
283
From = 60 ,
282
284
To = desktopWorkingArea . Height / 2 ,
283
285
Duration = new Duration ( TimeSpan . FromSeconds ( 0.5 ) ) ,
284
- EasingFunction = easeFunction ,
285
- } ;
286
- heightAnimation . Completed += delegate
287
- {
288
- BeginAnimation ( HeightProperty , null ) ;
286
+ EasingFunction = easeFunction
289
287
} ;
288
+ heightAnimation . Completed += delegate { BeginAnimation ( HeightProperty , null ) ; } ;
290
289
BeginAnimation ( WidthProperty , widthAnimation ) ;
291
290
BeginAnimation ( HeightProperty , heightAnimation ) ;
292
291
}
293
292
catch ( Exception ex )
294
293
{
295
294
Log . Error ( $ "MainView.UnToggleButtonMini_Checked{ ex . Message } ") ;
296
295
}
297
-
298
296
}
299
297
300
-
301
298
#endregion
302
-
303
- private void myNotifyIcon_TrayLeftMouseUp ( object sender , RoutedEventArgs e )
304
- {
305
- if ( mainVM . IsEmbedded ) return ;
306
- Show ( ) ;
307
- Activate ( ) ;
308
- Focus ( ) ;
309
- }
310
299
}
311
300
}
0 commit comments