星火微课系统客户端
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

ScreenRecordingToolbarWindow.xaml.cs 33KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880
  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 (gridToolbar.Visibility == Visibility.Visible)
  395. {
  396. gridToolbar.Visibility = Visibility.Hidden;
  397. gridColour.Visibility = Visibility.Hidden;
  398. gridThickness.Visibility = Visibility.Hidden;
  399. APP.W_PracticeWindow.Hide();
  400. }
  401. if (APP.W_XHMicroLessonSystemWindow == null)
  402. {
  403. APP.W_XHMicroLessonSystemWindow = new XHMicroLessonSystemWindow();
  404. }
  405. APP.W_XHMicroLessonSystemWindow.Show();
  406. if (!IsFirstRS)
  407. {
  408. try
  409. {
  410. try
  411. {
  412. APP.FFmpeg.StopFFmpeg(VideoSavePathName);
  413. }
  414. catch (Exception ex)
  415. {
  416. LogHelper.WriteErrLog("【停止录屏】(BtnStopRecordingScreen_Click)" + ex.Message, ex);
  417. }
  418. IsFirstRS = true;
  419. //生成缩略图
  420. string ThumbnailPath = FileToolsCommon.GetDirectoryName(VideoSavePathName) + "ThumbnailPath/";
  421. FileToolsCommon.CreateDirectory(ThumbnailPath);
  422. //缩略图存储位置
  423. string ThumbnailPathName = ThumbnailPath + FileToolsCommon.GetIOFileName(VideoSavePathName).Replace(".", "") + ".JPG";
  424. new Thread(new ThreadStart(new Action(() =>
  425. {
  426. while (!FileToolsCommon.IsExistFile(VideoSavePathName))
  427. {
  428. Thread.Sleep(100);
  429. }
  430. FileToolsCommon.DeleteFile(ThumbnailPathName);
  431. //VideoInfo.VideoSize = FileToolsCommon.GetFileSizeByMB(VideoSavePathName).ToString() + " MB";
  432. VideoInfo.RSTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  433. VideoInfo.VideoPath = VideoSavePathName;
  434. VideoInfo.ThumbnailPath = ThumbnailPathName;
  435. APP.FFmpeg.GenerateThumbnails(VideoSavePathName, ThumbnailPathName);
  436. VideoInfo.FileGuid = Guid.NewGuid().ToString();
  437. VideoInfo.IsUpload = false;
  438. VideoInfo.Uploaded = 0;
  439. VideoInfo.Savefolder = APP.UserInfo.Schoolid + "/resource";
  440. APP.VideoList.Add(VideoInfo);
  441. //保存数据
  442. APP.SaveWkData();
  443. }))).Start();
  444. Click_stopRecordingScreen();
  445. }
  446. catch (Exception ex)
  447. {
  448. LogHelper.WriteErrLog("【停止录屏】(BtnStopRecordingScreen_Click)" + ex.Message, ex);
  449. }
  450. }
  451. Hide();
  452. }
  453. #endregion
  454. #region 画笔相关
  455. /// <summary>
  456. /// 画笔工具栏关闭事件
  457. /// </summary>
  458. /// <param name="sender"></param>
  459. /// <param name="e"></param>
  460. private void BtnToolbarDown_Click(object sender, RoutedEventArgs e)
  461. {
  462. gridToolbar.Visibility = Visibility.Hidden;
  463. gridColour.Visibility = Visibility.Hidden;
  464. gridThickness.Visibility = Visibility.Hidden;
  465. APP.W_PracticeWindow.Hide();
  466. }
  467. /// <summary>
  468. /// 画笔点击事件
  469. /// </summary>
  470. /// <param name="sender"></param>
  471. /// <param name="e"></param>
  472. private void BtnBrush_Click(object sender, RoutedEventArgs e)
  473. {
  474. string time = GetTimeStamp();
  475. string tempPath = AppDomain.CurrentDomain.BaseDirectory + "temp\\";
  476. if (!Directory.Exists(tempPath))
  477. {
  478. Directory.CreateDirectory(tempPath);
  479. }
  480. string imagePath = Path.Combine(tempPath, time + ".jpg");
  481. ImageHelper.GetScreenshot(new System.Drawing.Rectangle(0, 0, 0, 0), imagePath, true, out BitmapImage bitmap);
  482. try
  483. {
  484. if (flg == 11)
  485. {
  486. flg = 1;
  487. APP.W_PracticeWindow.Hide();
  488. }
  489. else if (flg == 10)
  490. {
  491. APP.W_PracticeWindow.Blue();
  492. flg = 11;
  493. }
  494. else
  495. {
  496. if (APP.W_PracticeWindow == null)
  497. {
  498. APP.W_PracticeWindow = new PracticeWindow
  499. {
  500. //APP.W_PracticeWindow.Topmost = true;
  501. Width = pwidth,
  502. Height = pHeight,
  503. Left = 0,
  504. Top = 0
  505. };
  506. //practiceWin.Owner = this;
  507. }
  508. APP.W_PracticeWindow.Initialize(imagePath);
  509. flg = 11;
  510. APP.W_PracticeWindow.Blue();
  511. APP.W_PracticeWindow.Show();
  512. }
  513. }
  514. catch (Exception ex)
  515. {
  516. LogHelper.WriteErrLog("【批注(PracticeWindow)" + ex.Message, ex);
  517. }
  518. //imgCanvas.Source = new BitmapImage(new Uri(imagePath));
  519. }
  520. /// <summary>
  521. /// 屏幕宽
  522. /// </summary>
  523. internal double pwidth = SystemParameters.PrimaryScreenWidth;
  524. /// <summary>
  525. /// 屏幕高
  526. /// </summary>
  527. internal double pHeight = SystemParameters.PrimaryScreenHeight;
  528. /// <summary>
  529. /// 获取时间戳
  530. /// </summary>
  531. /// <returns></returns>
  532. public string GetTimeStamp()
  533. {
  534. TimeSpan ts = DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0, 0);
  535. return Convert.ToInt64(ts.TotalMilliseconds).ToString();
  536. }
  537. /// <summary>
  538. /// 画笔粗细事件
  539. /// </summary>
  540. /// <param name="sender"></param>
  541. /// <param name="e"></param>
  542. private void BtnThickness_Click(object sender, RoutedEventArgs e)
  543. {
  544. gridThickness.Visibility = Visibility.Visible;
  545. gridColour.Visibility = Visibility.Collapsed;
  546. }
  547. /// <summary>
  548. /// 画笔颜色事件
  549. /// </summary>
  550. /// <param name="sender"></param>
  551. /// <param name="e"></param>
  552. private void BtnColour_Click(object sender, RoutedEventArgs e)
  553. {
  554. gridColour.Visibility = Visibility.Visible;
  555. gridThickness.Visibility = Visibility.Collapsed;
  556. }
  557. /// <summary>
  558. /// 白色
  559. /// </summary>
  560. /// <param name="sender"></param>
  561. /// <param name="e"></param>
  562. private void BtnWhite_Click(object sender, RoutedEventArgs e)
  563. {
  564. //drawingAttributes.Color = Colors.White;
  565. APP.W_PracticeWindow.White();
  566. gridColour.Visibility = Visibility.Collapsed;
  567. gridThickness.Visibility = Visibility.Collapsed;
  568. }
  569. /// <summary>
  570. /// 红色
  571. /// </summary>
  572. /// <param name="sender"></param>
  573. /// <param name="e"></param>
  574. private void BtnRed_Click(object sender, RoutedEventArgs e)
  575. {
  576. //drawingAttributes.Color = Colors.Red;
  577. APP.W_PracticeWindow.Red();
  578. gridColour.Visibility = Visibility.Collapsed;
  579. gridThickness.Visibility = Visibility.Collapsed;
  580. }
  581. /// <summary>
  582. /// 黄色
  583. /// </summary>
  584. /// <param name="sender"></param>
  585. /// <param name="e"></param>
  586. private void BtnYellow_Click(object sender, RoutedEventArgs e)
  587. {
  588. //drawingAttributes.Color = Colors.Gold;
  589. APP.W_PracticeWindow.Yellow();
  590. gridColour.Visibility = Visibility.Collapsed;
  591. gridThickness.Visibility = Visibility.Collapsed;
  592. }
  593. /// <summary>
  594. /// 青色
  595. /// </summary>
  596. /// <param name="sender"></param>
  597. /// <param name="e"></param>
  598. private void BtnCyanBlue_Click(object sender, RoutedEventArgs e)
  599. {
  600. //drawingAttributes.Color = Colors.LimeGreen;
  601. APP.W_PracticeWindow.CyanBlue();
  602. gridColour.Visibility = Visibility.Collapsed;
  603. gridThickness.Visibility = Visibility.Collapsed;
  604. }
  605. /// <summary>
  606. /// 灰色
  607. /// </summary>
  608. /// <param name="sender"></param>
  609. /// <param name="e"></param>
  610. private void BtnGray_Click(object sender, RoutedEventArgs e)
  611. {
  612. //drawingAttributes.Color = Colors.Gray;
  613. APP.W_PracticeWindow.Gray();
  614. gridColour.Visibility = Visibility.Collapsed;
  615. gridThickness.Visibility = Visibility.Collapsed;
  616. }
  617. /// <summary>
  618. /// 蓝色
  619. /// </summary>
  620. /// <param name="sender"></param>
  621. /// <param name="e"></param>
  622. private void BtnBlue_Click(object sender, RoutedEventArgs e)
  623. {
  624. //drawingAttributes.Color = Colors.DeepSkyBlue;
  625. APP.W_PracticeWindow.Blue();
  626. gridColour.Visibility = Visibility.Collapsed;
  627. gridThickness.Visibility = Visibility.Collapsed;
  628. }
  629. /// <summary>
  630. /// 画笔 细
  631. /// </summary>
  632. /// <param name="sender"></param>
  633. /// <param name="e"></param>
  634. private void BtnFine_Click(object sender, RoutedEventArgs e)
  635. {
  636. APP.W_PracticeWindow.Fine();
  637. gridColour.Visibility = Visibility.Collapsed;
  638. gridThickness.Visibility = Visibility.Collapsed;
  639. }
  640. /// <summary>
  641. /// 画笔 中
  642. /// </summary>
  643. /// <param name="sender"></param>
  644. /// <param name="e"></param>
  645. private void BtnIn_Click(object sender, RoutedEventArgs e)
  646. {
  647. APP.W_PracticeWindow.In();
  648. gridColour.Visibility = Visibility.Collapsed;
  649. gridThickness.Visibility = Visibility.Collapsed;
  650. }
  651. /// <summary>
  652. /// 画笔粗
  653. /// </summary>
  654. /// <param name="sender"></param>
  655. /// <param name="e"></param>
  656. private void BtnCrude_Click(object sender, RoutedEventArgs e)
  657. {
  658. APP.W_PracticeWindow.Crude();
  659. gridColour.Visibility = Visibility.Collapsed;
  660. gridThickness.Visibility = Visibility.Collapsed;
  661. }
  662. /// <summary>
  663. /// 橡皮
  664. /// </summary>
  665. /// <param name="sender"></param>
  666. /// <param name="e"></param>
  667. private void BtnEraser_Click(object sender, RoutedEventArgs e)
  668. {
  669. APP.W_PracticeWindow.Eraser();
  670. }
  671. /// <summary>
  672. /// 🖊
  673. /// </summary>
  674. /// <param name="sender"></param>
  675. /// <param name="e"></param>
  676. private void BtnPen_Click(object sender, RoutedEventArgs e)
  677. {
  678. APP.W_PracticeWindow.Pen();
  679. }
  680. /// <summary>
  681. /// ⚪
  682. /// </summary>
  683. /// <param name="sender"></param>
  684. /// <param name="e"></param>
  685. private void BtnRound_Click(object sender, RoutedEventArgs e)
  686. {
  687. APP.W_PracticeWindow.Round();
  688. }
  689. /// <summary>
  690. /// 矩形
  691. /// </summary>
  692. /// <param name="sender"></param>
  693. /// <param name="e"></param>
  694. private void BtnRectangle_Click(object sender, RoutedEventArgs e)
  695. {
  696. APP.W_PracticeWindow.Rectangle();
  697. }
  698. #endregion
  699. #endregion
  700. /// <summary>
  701. /// 停止录屏
  702. /// </summary>
  703. public delegate void StopRecordingScreen();
  704. /// <summary>
  705. /// 停止录屏
  706. /// </summary>
  707. public event StopRecordingScreen Click_stopRecordingScreen;
  708. /// <summary>
  709. /// 黑笔
  710. /// </summary>
  711. /// <param name="sender"></param>
  712. /// <param name="e"></param>
  713. private void BtnBlackPen_Click(object sender, RoutedEventArgs e)
  714. {
  715. }
  716. /// <summary>
  717. /// 移动工具栏
  718. /// </summary>
  719. /// <param name="sender"></param>
  720. /// <param name="e"></param>
  721. private void Grid_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
  722. {
  723. DragMove();
  724. }
  725. /// <summary>
  726. /// 红笔
  727. /// </summary>
  728. /// <param name="sender"></param>
  729. /// <param name="e"></param>
  730. private void BtnBlackPenTwo_Click(object sender, RoutedEventArgs e)
  731. {
  732. string time = GetTimeStamp();
  733. string tempPath = AppDomain.CurrentDomain.BaseDirectory + "temp\\";
  734. if (!Directory.Exists(tempPath))
  735. {
  736. Directory.CreateDirectory(tempPath);
  737. }
  738. string imagePath = Path.Combine(tempPath, time + ".jpg");
  739. ImageHelper.GetScreenshot(new System.Drawing.Rectangle(0, 0, 0, 0), imagePath, true, out BitmapImage bitmap);
  740. try
  741. {
  742. if (flg == 10)
  743. {
  744. flg = 0;
  745. APP.W_PracticeWindow.Hide();
  746. }
  747. else if (flg == 11)
  748. {
  749. flg = 10;
  750. APP.W_PracticeWindow.Red();
  751. }
  752. else
  753. {
  754. if (APP.W_PracticeWindow == null)
  755. {
  756. APP.W_PracticeWindow = new PracticeWindow
  757. {
  758. //APP.W_PracticeWindow.Topmost = true;
  759. Width = pwidth,
  760. Height = pHeight,
  761. Left = 0,
  762. Top = 0
  763. };
  764. //practiceWin.Owner = this;
  765. }
  766. APP.W_PracticeWindow.Initialize(imagePath);
  767. flg = 10;
  768. APP.W_PracticeWindow.Red();
  769. APP.W_PracticeWindow.Show();
  770. }
  771. }
  772. catch (Exception ex)
  773. {
  774. LogHelper.WriteErrLog("【批注(PracticeWindow)" + ex.Message, ex);
  775. }
  776. }
  777. /// <summary>
  778. /// 鼠标右键按下事件
  779. /// </summary>
  780. /// <param name="sender"></param>
  781. /// <param name="e"></param>
  782. private void RightButtonDown()
  783. {
  784. if (flg > 9)
  785. {
  786. APP.W_PracticeWindow.Hide();
  787. }
  788. else
  789. {
  790. string time = GetTimeStamp();
  791. string tempPath = AppDomain.CurrentDomain.BaseDirectory + "temp\\";
  792. if (!Directory.Exists(tempPath))
  793. {
  794. Directory.CreateDirectory(tempPath);
  795. }
  796. string imagePath = Path.Combine(tempPath, time + ".jpg");
  797. ImageHelper.GetScreenshot(new System.Drawing.Rectangle(0, 0, 0, 0), imagePath, true, out BitmapImage bitmap);
  798. try
  799. {
  800. if (APP.W_PracticeWindow == null)
  801. {
  802. APP.W_PracticeWindow = new PracticeWindow
  803. {
  804. //APP.W_PracticeWindow.Topmost = true;
  805. Width = pwidth,
  806. Height = pHeight,
  807. Left = 0,
  808. Top = 0
  809. };
  810. //practiceWin.Owner = this;
  811. }
  812. APP.W_PracticeWindow.Initialize(imagePath);
  813. if (flg == 0)
  814. {
  815. flg = 10;
  816. APP.W_PracticeWindow.Red();
  817. }
  818. else
  819. {
  820. flg = 11;
  821. APP.W_PracticeWindow.Blue();
  822. }
  823. APP.W_PracticeWindow.Show();
  824. }
  825. catch (Exception ex)
  826. {
  827. LogHelper.WriteErrLog("【批注(PracticeWindow)" + ex.Message, ex);
  828. }
  829. }
  830. }
  831. /// <summary>
  832. /// 返回主界面
  833. /// </summary>
  834. /// <param name="sender"></param>
  835. /// <param name="e"></param>
  836. private void BtnReturn_Click(object sender, RoutedEventArgs e)
  837. {
  838. if (APP.W_XHMicroLessonSystemWindow == null)
  839. {
  840. APP.W_XHMicroLessonSystemWindow = new XHMicroLessonSystemWindow();
  841. }
  842. APP.W_XHMicroLessonSystemWindow.Show();
  843. Hide();
  844. }
  845. }
  846. }