星火微课系统客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ScreenRecordingToolbarWindow.xaml.cs 33KB

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