星火微课系统客户端
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

ScreenRecordingToolbarWindow.xaml.cs 33KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887
  1. using Common.system;
  2. using System;
  3. using System.IO;
  4. using System.Threading;
  5. using System.Windows;
  6. using System.Windows.Forms;
  7. using System.Windows.Ink;
  8. using System.Windows.Media.Imaging;
  9. using System.Windows.Threading;
  10. using XHWK.Model;
  11. namespace XHWK.WKTool
  12. {
  13. /// <summary>
  14. /// 录屏工具栏
  15. /// </summary>
  16. public partial class ScreenRecordingToolbarWindow : Window
  17. {
  18. #region 初始变量
  19. /// <summary>
  20. /// 视频保存名称
  21. /// </summary>
  22. private string VideoSavePathName;
  23. /// <summary>
  24. /// 是否首次录屏
  25. /// </summary>
  26. private bool IsFirstRS = true;
  27. /// <summary>
  28. /// 是否暂停
  29. /// </summary>
  30. private bool IsSuspend = true;
  31. /// <summary>
  32. /// 视频信息
  33. /// </summary>
  34. private Model_Video VideoInfo = null;
  35. //声明一个 DrawingAttributes 类型的变量
  36. private DrawingAttributes drawingAttributes;
  37. private DispatcherTimer t = null;
  38. /// <summary>
  39. /// 计时器状态
  40. /// </summary>
  41. private enum State
  42. {
  43. Start,
  44. Pause,
  45. End
  46. }
  47. /// <summary>
  48. /// 状态
  49. /// </summary>
  50. private State _state = State.End;
  51. /// <summary>
  52. /// 计时用
  53. /// </summary>
  54. private TimeSpan _timeSpan = new TimeSpan(0, 0, 0, 0, 0);
  55. private KeyboardHookCommon k_hook;
  56. /// <summary>
  57. /// 🖊状态 0红色 1蓝色 10红色批注内 11蓝色批注内
  58. /// </summary>
  59. public int flg = 0;
  60. private System.Timers.Timer timer = new System.Timers.Timer();
  61. #endregion
  62. #region 初始化
  63. /// <summary>
  64. /// 录屏工具栏
  65. /// </summary>
  66. public ScreenRecordingToolbarWindow()
  67. {
  68. InitializeComponent();
  69. }
  70. /// <summary>
  71. /// 初始化
  72. /// </summary>
  73. public void Initialize()
  74. {
  75. //timer = new System.Timers.Timer(200);
  76. //timer.Interval = 300;
  77. //timer.Elapsed += new System.Timers.ElapsedEventHandler(TimerDealy);
  78. //timer.Enabled = true; //启动计时器
  79. k_hook = new KeyboardHookCommon();
  80. k_hook.KeyDownEvent += K_hook_KeyDownEvent;
  81. //创建 DrawingAttributes 类的一个实例
  82. drawingAttributes = new DrawingAttributes();
  83. //将 InkCanvas 的 DefaultDrawingAttributes 属性的值赋成创建的 DrawingAttributes 类的对象的引用
  84. //InkCanvas 通过 DefaultDrawingAttributes 属性来获取墨迹的各种设置,该属性的类型为 DrawingAttributes 型
  85. blackboard_canvas.DefaultDrawingAttributes = drawingAttributes;
  86. drawingAttributes.FitToCurve = true;
  87. //隐藏画笔工具栏
  88. //BtnToolbarDown_Click(null, null);
  89. gridToolbar.Visibility = Visibility.Hidden;
  90. gridColour.Visibility = Visibility.Hidden;
  91. gridThickness.Visibility = Visibility.Hidden;
  92. ImgRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar26.png"));//大圆圈三角形
  93. ImgEndRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar15.png"));
  94. BtnStopRecordingScreen.IsEnabled = false; //停止录制按钮不点击
  95. imgBlackPenOne.Source = new BitmapImage(new Uri("pack://application:,,,/Images/31.png"));
  96. btnBlackPenOne.IsEnabled = false;//蓝笔不可点击
  97. imgBlackPenTwo.Source = new BitmapImage(new Uri("pack://application:,,,/Images/31.png"));
  98. btnBlackPenTwo.IsEnabled = false;//红笔不可点击
  99. imgReturn.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar29.png"));
  100. btnReturn.IsEnabled = true;//返回主界面可点击
  101. txbTime.Visibility = Visibility.Hidden;//时间不显示
  102. if (t == null)
  103. {
  104. t = new DispatcherTimer();
  105. t.Tick += OnTimer;
  106. t.Interval = new TimeSpan(0, 0, 0, 1);
  107. t.IsEnabled = true;
  108. t.Start();
  109. }
  110. t.Interval = new TimeSpan(0, 0, 0, 1);
  111. //Stack();
  112. //ImgRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar25.png"));
  113. //BtnRecordingScreen_Click(null, null);
  114. }
  115. private void TimerDealy(object o, EventArgs e)
  116. {
  117. Dispatcher.Invoke(() =>
  118. {
  119. if (Left > 1630)
  120. {
  121. return;
  122. }
  123. //获取鼠标在屏幕上的位置
  124. double mouse_x = Form.MousePosition.X; //需要添加引用System.Drawing
  125. double mouse_y = Form.MousePosition.Y;
  126. bool is_in_collasped_range = (mouse_y > Left + Height) || (mouse_x < Left || mouse_x > Left + Width);//缩起的条件
  127. bool is_in_visiable_range = (mouse_y < 1 && mouse_x >= Left && mouse_x <= Left + Width); //展开的条件
  128. if (Left < 1630 && Left >= 0 && is_in_collasped_range)
  129. {
  130. System.Threading.Thread.Sleep(300);
  131. Left += 20 /*-this.ActualWidth - 3*/;
  132. }
  133. else if (Left < 0 && is_in_visiable_range)
  134. {
  135. Left = 1;
  136. }
  137. });
  138. }
  139. private void K_hook_KeyDownEvent(object sender, System.Windows.Forms.KeyEventArgs e)
  140. {
  141. if (e.KeyValue == (int)System.Windows.Forms.Keys.F5 && (int)Control.ModifierKeys == (int)Keys.Control)
  142. {
  143. //开始,暂停
  144. BtnRecordingScreen_Click(null, null);
  145. }
  146. if (e.KeyValue == (int)Keys.S && (int)Control.ModifierKeys == (int)Keys.Control)
  147. {
  148. //结束
  149. BtnStopRecordingScreen_Click(null, null);
  150. }
  151. }
  152. #endregion
  153. #region 事件
  154. /// <summary>
  155. /// 时钟回调
  156. /// </summary>
  157. /// <param name="sender"></param>
  158. /// <param name="e"></param>
  159. private void OnTimer(object sender, EventArgs e)
  160. {
  161. switch (_state)
  162. {
  163. case State.Start:
  164. {
  165. _timeSpan += new TimeSpan(0, 0, 0, 1);
  166. }
  167. break;
  168. case State.Pause:
  169. {
  170. }
  171. break;
  172. case State.End:
  173. {
  174. _timeSpan = new TimeSpan();
  175. //_timeSpan = new TimeSpan(0, 23, 12, 45, 54);
  176. }
  177. break;
  178. }
  179. string time = string.Format("{0:D2}:{1:D2}",/* _timeSpan.Hours,*/ _timeSpan.Minutes, _timeSpan.Seconds);
  180. //char[] times = time.ToCharArray();
  181. txbTime.Text = time;
  182. }
  183. /// <summary>
  184. /// 开始
  185. /// </summary>
  186. /// <param name="sender"></param>
  187. /// <param name="e"></param>
  188. private void Stack()
  189. {
  190. _state = State.Start;
  191. }
  192. /// <summary>
  193. /// 暂停
  194. /// </summary>
  195. private void TimeOut()
  196. {
  197. _state = State.Pause;
  198. }
  199. /// <summary>
  200. /// 结束
  201. /// </summary>
  202. /// <param name="sender"></param>
  203. /// <param name="e"></param>
  204. private void End()
  205. {
  206. _state = State.End;
  207. }
  208. #region 录屏
  209. /// <summary>
  210. /// 设置录屏文件地址
  211. /// </summary>
  212. private void SetUpVideoPathName()
  213. {
  214. //FileToolsCommon.DeleteDirectory(APP.WKData.WkPath + "temp/");
  215. FileToolsCommon.CreateDirectory(APP.WKData.WkPath);
  216. FileToolsCommon.DeleteDirectory(APP.WKData.WkPath + "tempsr/");
  217. VideoSavePathName = APP.WKData.WkPath + APP.WKData.WkName + "_录屏." + ((Enum_VideoType)int.Parse(FileToolsCommon.GetConfigValue("VideoType"))).ToString();
  218. int num = 1;
  219. while (FileToolsCommon.IsExistFile(VideoSavePathName))
  220. {
  221. VideoSavePathName = APP.WKData.WkPath + APP.WKData.WkName + "_录屏_" + num + "." + ((Enum_VideoType)int.Parse(FileToolsCommon.GetConfigValue("VideoType"))).ToString();
  222. num++;
  223. }
  224. }
  225. /// <summary>
  226. /// 开始或暂停录制
  227. /// </summary>
  228. /// <param name="sender"></param>
  229. /// <param name="e"></param>
  230. private void BtnRecordingScreen_Click(object sender, RoutedEventArgs e)
  231. {
  232. if (IsSuspend)
  233. {
  234. if (IsFirstRS)
  235. {
  236. #region 检测麦克风扬声器是否可用
  237. string audioSpeakerPath = FileToolsCommon.GetFileAbsolutePath("adoS.m");
  238. string audioMicrophonePath = FileToolsCommon.GetFileAbsolutePath("adoM.m");
  239. try
  240. {
  241. FileToolsCommon.DeleteFile(audioSpeakerPath);
  242. FileToolsCommon.DeleteFile(audioMicrophonePath);
  243. }
  244. catch (Exception)
  245. {
  246. }
  247. //扬声器
  248. if (APP.FFmpeg.StartRecordSpeakerAudio(audioSpeakerPath))
  249. {
  250. APP.FFmpeg.StopRecordAudio();
  251. //Thread.Sleep(500);
  252. //麦克风
  253. if (APP.FFmpeg.StartRecordAudio(audioMicrophonePath))
  254. {
  255. }
  256. else
  257. {
  258. //无法录制麦克风
  259. MessageBoxResult Res = MessageWindow.Show("当前电脑无法录制麦克风,是否继续?", "消息提示", MessageBoxButton.OKCancel);
  260. if (Res == MessageBoxResult.Cancel)
  261. {
  262. return;
  263. }
  264. }
  265. APP.FFmpeg.StopRecordAudio();
  266. }
  267. else
  268. {
  269. //无法录制扬声器音频
  270. MessageBoxResult Res = MessageWindow.Show("当前电脑无法录制音频,是否继续?", "消息提示", MessageBoxButton.OKCancel);
  271. if (Res == MessageBoxResult.Cancel)
  272. {
  273. return;
  274. }
  275. }
  276. #endregion
  277. VideoInfo = new Model_Video
  278. {
  279. VideoType = (Enum_VideoType)int.Parse(FileToolsCommon.GetConfigValue("VideoType")),
  280. WkType = Enum_WKVidetype.RecordingScreen
  281. };
  282. SetUpVideoPathName();
  283. IsFirstRS = false;
  284. k_hook.Start();//安装键盘钩子
  285. if (APP.W_CountdownWindow == null)
  286. {
  287. APP.W_CountdownWindow = new CountdownWindow();
  288. APP.W_CountdownWindow.Initialize(true, 1800);
  289. //APP.W_CountdownWindow.Topmost = true;
  290. }
  291. else
  292. {
  293. APP.W_CountdownWindow.Initialize(true, 1800);
  294. //APP.W_CountdownWindow.Topmost = true;
  295. }
  296. APP.W_CountdownWindow.Show();
  297. }
  298. IsSuspend = false;
  299. //#region 录像倒计时
  300. //if (APP.W_CountdownWindow == null)
  301. //{
  302. // APP.W_CountdownWindow = new CountdownWindow();
  303. // //APP.W_CountdownWindow.Topmost = true;
  304. //}
  305. //else
  306. //{
  307. // APP.W_CountdownWindow.Initialize();
  308. // //APP.W_CountdownWindow.Topmost = true;
  309. //}
  310. //APP.W_CountdownWindow.Show();
  311. //#endregion
  312. ImgRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar25.png"));//播放状态
  313. ImgEndRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar14.png"));
  314. BtnStopRecordingScreen.IsEnabled = true; //停止录制按钮可点击
  315. imgBlackPenOne.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar27.png"));
  316. btnBlackPenOne.IsEnabled = true;//蓝笔可点击
  317. imgBlackPenTwo.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar28.png"));
  318. btnBlackPenTwo.IsEnabled = true;//红笔可点击
  319. imgReturn.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar30.png"));
  320. btnReturn.IsEnabled = false;//返回主界面不可点击
  321. txbTime.Visibility = Visibility.Visible;//时间显示
  322. try
  323. {
  324. new Thread(new ThreadStart(new Action(() =>
  325. {
  326. if (IsFirstRS)
  327. {
  328. Thread.Sleep(1500);
  329. }
  330. APP.FFmpeg.StartRecordingVideo(VideoSavePathName);
  331. Thread.Sleep(1000);
  332. Dispatcher.Invoke(() =>
  333. {
  334. Stack();
  335. });
  336. }))).Start();
  337. }
  338. catch (Exception ex)
  339. {
  340. MessageWindow.Show(ex.Message);
  341. }
  342. }
  343. else
  344. {
  345. TimeOut();
  346. IsSuspend = true;
  347. ImgRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar26.png"));//大圆圈三角形
  348. ImgEndRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar15.png"));
  349. BtnStopRecordingScreen.IsEnabled = false; //停止录制按钮不点击
  350. imgBlackPenOne.Source = new BitmapImage(new Uri("pack://application:,,,/Images/31.png"));
  351. btnBlackPenOne.IsEnabled = false;//蓝笔不可点击
  352. imgBlackPenTwo.Source = new BitmapImage(new Uri("pack://application:,,,/Images/31.png"));
  353. btnBlackPenTwo.IsEnabled = false;//红笔不可点击
  354. txbTime.Visibility = Visibility.Hidden;//时间不显示
  355. #region 2秒内不可点击
  356. new Thread(new ThreadStart(new Action(() =>
  357. {
  358. Dispatcher.Invoke(() =>
  359. {
  360. BtnRecordingScreen.IsEnabled = false;
  361. BtnStopRecordingScreen.IsEnabled = false;
  362. });
  363. Thread.Sleep(2000);
  364. Dispatcher.Invoke(() =>
  365. {
  366. ImgEndRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar14.png"));
  367. BtnRecordingScreen.IsEnabled = true;
  368. BtnStopRecordingScreen.IsEnabled = true;
  369. });
  370. }))).Start();
  371. #endregion
  372. try
  373. {
  374. APP.FFmpeg.SuspendFFmpeg();
  375. }
  376. catch (Exception ex)
  377. {
  378. MessageWindow.Show(ex.Message);
  379. }
  380. }
  381. }
  382. /// <summary>
  383. /// 停止录像
  384. /// </summary>
  385. /// <param name="sender"></param>
  386. /// <param name="e"></param>
  387. private void BtnStopRecordingScreen_Click(object sender, RoutedEventArgs e)
  388. {
  389. k_hook.Stop();
  390. IsSuspend = true;
  391. txbTime.Text = "00:00";
  392. txbTime.Visibility = Visibility.Hidden;
  393. End();
  394. if (APP.W_PracticeWindow != null)
  395. {
  396. if (APP.W_PracticeWindow.Visibility == Visibility.Visible)
  397. {
  398. APP.W_PracticeWindow.Hide();
  399. }
  400. }
  401. if (gridToolbar.Visibility == Visibility.Visible)
  402. {
  403. gridToolbar.Visibility = Visibility.Hidden;
  404. gridColour.Visibility = Visibility.Hidden;
  405. gridThickness.Visibility = Visibility.Hidden;
  406. }
  407. if (APP.W_XHMicroLessonSystemWindow == null)
  408. {
  409. APP.W_XHMicroLessonSystemWindow = new XHMicroLessonSystemWindow();
  410. }
  411. APP.W_XHMicroLessonSystemWindow.Show();
  412. if (!IsFirstRS)
  413. {
  414. try
  415. {
  416. try
  417. {
  418. APP.FFmpeg.StopFFmpeg(VideoSavePathName);
  419. }
  420. catch (Exception ex)
  421. {
  422. LogHelper.WriteErrLog("【停止录屏】(BtnStopRecordingScreen_Click)" + ex.Message, ex);
  423. }
  424. IsFirstRS = true;
  425. //生成缩略图
  426. string ThumbnailPath = FileToolsCommon.GetDirectoryName(VideoSavePathName) + "ThumbnailPath/";
  427. FileToolsCommon.CreateDirectory(ThumbnailPath);
  428. //缩略图存储位置
  429. string ThumbnailPathName = ThumbnailPath + FileToolsCommon.GetIOFileName(VideoSavePathName).Replace(".", "") + ".JPG";
  430. new Thread(new ThreadStart(new Action(() =>
  431. {
  432. while (!FileToolsCommon.IsExistFile(VideoSavePathName))
  433. {
  434. Thread.Sleep(100);
  435. }
  436. FileToolsCommon.DeleteFile(ThumbnailPathName);
  437. //VideoInfo.VideoSize = FileToolsCommon.GetFileSizeByMB(VideoSavePathName).ToString() + " MB";
  438. VideoInfo.RSTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  439. VideoInfo.VideoPath = VideoSavePathName;
  440. VideoInfo.ThumbnailPath = ThumbnailPathName;
  441. APP.FFmpeg.GenerateThumbnails(VideoSavePathName, ThumbnailPathName);
  442. VideoInfo.FileGuid = Guid.NewGuid().ToString();
  443. VideoInfo.IsUpload = false;
  444. VideoInfo.Uploaded = 0;
  445. VideoInfo.Savefolder = APP.UserInfo.Schoolid + "/resource";
  446. APP.VideoList.Add(VideoInfo);
  447. //保存数据
  448. APP.SaveWkData();
  449. }))).Start();
  450. Click_stopRecordingScreen();
  451. }
  452. catch (Exception ex)
  453. {
  454. LogHelper.WriteErrLog("【停止录屏】(BtnStopRecordingScreen_Click)" + ex.Message, ex);
  455. }
  456. }
  457. Hide();
  458. }
  459. #endregion
  460. #region 画笔相关
  461. /// <summary>
  462. /// 画笔工具栏关闭事件
  463. /// </summary>
  464. /// <param name="sender"></param>
  465. /// <param name="e"></param>
  466. private void BtnToolbarDown_Click(object sender, RoutedEventArgs e)
  467. {
  468. gridToolbar.Visibility = Visibility.Hidden;
  469. gridColour.Visibility = Visibility.Hidden;
  470. gridThickness.Visibility = Visibility.Hidden;
  471. APP.W_PracticeWindow.Hide();
  472. }
  473. /// <summary>
  474. /// 画笔点击事件
  475. /// </summary>
  476. /// <param name="sender"></param>
  477. /// <param name="e"></param>
  478. private void BtnBrush_Click(object sender, RoutedEventArgs e)
  479. {
  480. string time = GetTimeStamp();
  481. string tempPath = AppDomain.CurrentDomain.BaseDirectory + "temp\\";
  482. if (!Directory.Exists(tempPath))
  483. {
  484. Directory.CreateDirectory(tempPath);
  485. }
  486. string imagePath = Path.Combine(tempPath, time + ".jpg");
  487. ImageHelper.GetScreenshot(new System.Drawing.Rectangle(0, 0, 0, 0), imagePath, true, out BitmapImage bitmap);
  488. try
  489. {
  490. if (flg == 11)
  491. {
  492. flg = 1;
  493. APP.W_PracticeWindow.Hide();
  494. }
  495. else if (flg == 10)
  496. {
  497. APP.W_PracticeWindow.Blue();
  498. flg = 11;
  499. }
  500. else
  501. {
  502. if (APP.W_PracticeWindow == null)
  503. {
  504. APP.W_PracticeWindow = new PracticeWindow
  505. {
  506. //APP.W_PracticeWindow.Topmost = true;
  507. Width = pwidth,
  508. Height = pHeight,
  509. Left = 0,
  510. Top = 0
  511. };
  512. //practiceWin.Owner = this;
  513. }
  514. APP.W_PracticeWindow.Initialize(imagePath);
  515. flg = 11;
  516. APP.W_PracticeWindow.Blue();
  517. APP.W_PracticeWindow.Show();
  518. }
  519. }
  520. catch (Exception ex)
  521. {
  522. LogHelper.WriteErrLog("【批注(PracticeWindow)" + ex.Message, ex);
  523. }
  524. //imgCanvas.Source = new BitmapImage(new Uri(imagePath));
  525. }
  526. /// <summary>
  527. /// 屏幕宽
  528. /// </summary>
  529. internal double pwidth = SystemParameters.PrimaryScreenWidth;
  530. /// <summary>
  531. /// 屏幕高
  532. /// </summary>
  533. internal double pHeight = SystemParameters.PrimaryScreenHeight;
  534. /// <summary>
  535. /// 获取时间戳
  536. /// </summary>
  537. /// <returns></returns>
  538. public string GetTimeStamp()
  539. {
  540. TimeSpan ts = DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0, 0);
  541. return Convert.ToInt64(ts.TotalMilliseconds).ToString();
  542. }
  543. /// <summary>
  544. /// 画笔粗细事件
  545. /// </summary>
  546. /// <param name="sender"></param>
  547. /// <param name="e"></param>
  548. private void BtnThickness_Click(object sender, RoutedEventArgs e)
  549. {
  550. gridThickness.Visibility = Visibility.Visible;
  551. gridColour.Visibility = Visibility.Collapsed;
  552. }
  553. /// <summary>
  554. /// 画笔颜色事件
  555. /// </summary>
  556. /// <param name="sender"></param>
  557. /// <param name="e"></param>
  558. private void BtnColour_Click(object sender, RoutedEventArgs e)
  559. {
  560. gridColour.Visibility = Visibility.Visible;
  561. gridThickness.Visibility = Visibility.Collapsed;
  562. }
  563. /// <summary>
  564. /// 白色
  565. /// </summary>
  566. /// <param name="sender"></param>
  567. /// <param name="e"></param>
  568. private void BtnWhite_Click(object sender, RoutedEventArgs e)
  569. {
  570. //drawingAttributes.Color = Colors.White;
  571. APP.W_PracticeWindow.White();
  572. gridColour.Visibility = Visibility.Collapsed;
  573. gridThickness.Visibility = Visibility.Collapsed;
  574. }
  575. /// <summary>
  576. /// 红色
  577. /// </summary>
  578. /// <param name="sender"></param>
  579. /// <param name="e"></param>
  580. private void BtnRed_Click(object sender, RoutedEventArgs e)
  581. {
  582. //drawingAttributes.Color = Colors.Red;
  583. APP.W_PracticeWindow.Red();
  584. gridColour.Visibility = Visibility.Collapsed;
  585. gridThickness.Visibility = Visibility.Collapsed;
  586. }
  587. /// <summary>
  588. /// 黄色
  589. /// </summary>
  590. /// <param name="sender"></param>
  591. /// <param name="e"></param>
  592. private void BtnYellow_Click(object sender, RoutedEventArgs e)
  593. {
  594. //drawingAttributes.Color = Colors.Gold;
  595. APP.W_PracticeWindow.Yellow();
  596. gridColour.Visibility = Visibility.Collapsed;
  597. gridThickness.Visibility = Visibility.Collapsed;
  598. }
  599. /// <summary>
  600. /// 青色
  601. /// </summary>
  602. /// <param name="sender"></param>
  603. /// <param name="e"></param>
  604. private void BtnCyanBlue_Click(object sender, RoutedEventArgs e)
  605. {
  606. //drawingAttributes.Color = Colors.LimeGreen;
  607. APP.W_PracticeWindow.CyanBlue();
  608. gridColour.Visibility = Visibility.Collapsed;
  609. gridThickness.Visibility = Visibility.Collapsed;
  610. }
  611. /// <summary>
  612. /// 灰色
  613. /// </summary>
  614. /// <param name="sender"></param>
  615. /// <param name="e"></param>
  616. private void BtnGray_Click(object sender, RoutedEventArgs e)
  617. {
  618. //drawingAttributes.Color = Colors.Gray;
  619. APP.W_PracticeWindow.Gray();
  620. gridColour.Visibility = Visibility.Collapsed;
  621. gridThickness.Visibility = Visibility.Collapsed;
  622. }
  623. /// <summary>
  624. /// 蓝色
  625. /// </summary>
  626. /// <param name="sender"></param>
  627. /// <param name="e"></param>
  628. private void BtnBlue_Click(object sender, RoutedEventArgs e)
  629. {
  630. //drawingAttributes.Color = Colors.DeepSkyBlue;
  631. APP.W_PracticeWindow.Blue();
  632. gridColour.Visibility = Visibility.Collapsed;
  633. gridThickness.Visibility = Visibility.Collapsed;
  634. }
  635. /// <summary>
  636. /// 画笔 细
  637. /// </summary>
  638. /// <param name="sender"></param>
  639. /// <param name="e"></param>
  640. private void BtnFine_Click(object sender, RoutedEventArgs e)
  641. {
  642. APP.W_PracticeWindow.Fine();
  643. gridColour.Visibility = Visibility.Collapsed;
  644. gridThickness.Visibility = Visibility.Collapsed;
  645. }
  646. /// <summary>
  647. /// 画笔 中
  648. /// </summary>
  649. /// <param name="sender"></param>
  650. /// <param name="e"></param>
  651. private void BtnIn_Click(object sender, RoutedEventArgs e)
  652. {
  653. APP.W_PracticeWindow.In();
  654. gridColour.Visibility = Visibility.Collapsed;
  655. gridThickness.Visibility = Visibility.Collapsed;
  656. }
  657. /// <summary>
  658. /// 画笔粗
  659. /// </summary>
  660. /// <param name="sender"></param>
  661. /// <param name="e"></param>
  662. private void BtnCrude_Click(object sender, RoutedEventArgs e)
  663. {
  664. APP.W_PracticeWindow.Crude();
  665. gridColour.Visibility = Visibility.Collapsed;
  666. gridThickness.Visibility = Visibility.Collapsed;
  667. }
  668. /// <summary>
  669. /// 橡皮
  670. /// </summary>
  671. /// <param name="sender"></param>
  672. /// <param name="e"></param>
  673. private void BtnEraser_Click(object sender, RoutedEventArgs e)
  674. {
  675. APP.W_PracticeWindow.Eraser();
  676. }
  677. /// <summary>
  678. /// 🖊
  679. /// </summary>
  680. /// <param name="sender"></param>
  681. /// <param name="e"></param>
  682. private void BtnPen_Click(object sender, RoutedEventArgs e)
  683. {
  684. APP.W_PracticeWindow.Pen();
  685. }
  686. /// <summary>
  687. /// ⚪
  688. /// </summary>
  689. /// <param name="sender"></param>
  690. /// <param name="e"></param>
  691. private void BtnRound_Click(object sender, RoutedEventArgs e)
  692. {
  693. APP.W_PracticeWindow.Round();
  694. }
  695. /// <summary>
  696. /// 矩形
  697. /// </summary>
  698. /// <param name="sender"></param>
  699. /// <param name="e"></param>
  700. private void BtnRectangle_Click(object sender, RoutedEventArgs e)
  701. {
  702. APP.W_PracticeWindow.Rectangle();
  703. }
  704. #endregion
  705. #endregion
  706. /// <summary>
  707. /// 停止录屏
  708. /// </summary>
  709. public delegate void StopRecordingScreen();
  710. /// <summary>
  711. /// 停止录屏
  712. /// </summary>
  713. public event StopRecordingScreen Click_stopRecordingScreen;
  714. /// <summary>
  715. /// 黑笔
  716. /// </summary>
  717. /// <param name="sender"></param>
  718. /// <param name="e"></param>
  719. private void BtnBlackPen_Click(object sender, RoutedEventArgs e)
  720. {
  721. }
  722. /// <summary>
  723. /// 移动工具栏
  724. /// </summary>
  725. /// <param name="sender"></param>
  726. /// <param name="e"></param>
  727. private void Grid_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
  728. {
  729. DragMove();
  730. }
  731. /// <summary>
  732. /// 红笔
  733. /// </summary>
  734. /// <param name="sender"></param>
  735. /// <param name="e"></param>
  736. private void BtnBlackPenTwo_Click(object sender, RoutedEventArgs e)
  737. {
  738. string time = GetTimeStamp();
  739. string tempPath = AppDomain.CurrentDomain.BaseDirectory + "temp\\";
  740. if (!Directory.Exists(tempPath))
  741. {
  742. Directory.CreateDirectory(tempPath);
  743. }
  744. string imagePath = Path.Combine(tempPath, time + ".jpg");
  745. ImageHelper.GetScreenshot(new System.Drawing.Rectangle(0, 0, 0, 0), imagePath, true, out BitmapImage bitmap);
  746. try
  747. {
  748. if (flg == 10)
  749. {
  750. flg = 0;
  751. APP.W_PracticeWindow.Hide();
  752. }
  753. else if (flg == 11)
  754. {
  755. flg = 10;
  756. APP.W_PracticeWindow.Red();
  757. }
  758. else
  759. {
  760. if (APP.W_PracticeWindow == null)
  761. {
  762. APP.W_PracticeWindow = new PracticeWindow
  763. {
  764. //APP.W_PracticeWindow.Topmost = true;
  765. Width = pwidth,
  766. Height = pHeight,
  767. Left = 0,
  768. Top = 0
  769. };
  770. //practiceWin.Owner = this;
  771. }
  772. APP.W_PracticeWindow.Initialize(imagePath);
  773. flg = 10;
  774. APP.W_PracticeWindow.Red();
  775. APP.W_PracticeWindow.Show();
  776. }
  777. }
  778. catch (Exception ex)
  779. {
  780. LogHelper.WriteErrLog("【批注(PracticeWindow)" + ex.Message, ex);
  781. }
  782. }
  783. /// <summary>
  784. /// 鼠标右键按下事件
  785. /// </summary>
  786. /// <param name="sender"></param>
  787. /// <param name="e"></param>
  788. private void RightButtonDown()
  789. {
  790. if (flg > 9)
  791. {
  792. APP.W_PracticeWindow.Hide();
  793. }
  794. else
  795. {
  796. string time = GetTimeStamp();
  797. string tempPath = AppDomain.CurrentDomain.BaseDirectory + "temp\\";
  798. if (!Directory.Exists(tempPath))
  799. {
  800. Directory.CreateDirectory(tempPath);
  801. }
  802. string imagePath = Path.Combine(tempPath, time + ".jpg");
  803. ImageHelper.GetScreenshot(new System.Drawing.Rectangle(0, 0, 0, 0), imagePath, true, out BitmapImage bitmap);
  804. try
  805. {
  806. if (APP.W_PracticeWindow == null)
  807. {
  808. APP.W_PracticeWindow = new PracticeWindow
  809. {
  810. //APP.W_PracticeWindow.Topmost = true;
  811. Width = pwidth,
  812. Height = pHeight,
  813. Left = 0,
  814. Top = 0
  815. };
  816. //practiceWin.Owner = this;
  817. }
  818. APP.W_PracticeWindow.Initialize(imagePath);
  819. if (flg == 0)
  820. {
  821. flg = 10;
  822. APP.W_PracticeWindow.Red();
  823. }
  824. else
  825. {
  826. flg = 11;
  827. APP.W_PracticeWindow.Blue();
  828. }
  829. APP.W_PracticeWindow.Show();
  830. }
  831. catch (Exception ex)
  832. {
  833. LogHelper.WriteErrLog("【批注(PracticeWindow)" + ex.Message, ex);
  834. }
  835. }
  836. }
  837. /// <summary>
  838. /// 返回主界面
  839. /// </summary>
  840. /// <param name="sender"></param>
  841. /// <param name="e"></param>
  842. private void BtnReturn_Click(object sender, RoutedEventArgs e)
  843. {
  844. if (APP.W_XHMicroLessonSystemWindow == null)
  845. {
  846. APP.W_XHMicroLessonSystemWindow = new XHMicroLessonSystemWindow();
  847. }
  848. APP.W_XHMicroLessonSystemWindow.Show();
  849. Hide();
  850. }
  851. }
  852. }