FillDigitalSignatureControl.xaml.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710
  1. using ComPDFKit.DigitalSign;
  2. using ComPDFKit.Import;
  3. using ComPDFKit.PDFAnnotation;
  4. using ComPDFKit.PDFAnnotation.Form;
  5. using ComPDFKit.PDFDocument;
  6. using ComPDFKit.PDFPage;
  7. using Compdfkit_Tools.Helper;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Drawing;
  11. using System.Drawing.Imaging;
  12. using System.IO;
  13. using System.Reflection;
  14. using System.Runtime.InteropServices;
  15. using System.Text;
  16. using System.Windows;
  17. using System.Windows.Controls;
  18. using System.Windows.Controls.Primitives;
  19. using System.Windows.Ink;
  20. using System.Windows.Input;
  21. using System.Windows.Media;
  22. using System.Windows.Media.Imaging;
  23. using Pen = System.Windows.Media.Pen;
  24. using PixelFormat = System.Windows.Media.PixelFormat;
  25. using Point = System.Windows.Point;
  26. using Window = System.Windows.Window;
  27. namespace Compdfkit_Tools.PDFControl
  28. {
  29. /// <summary>
  30. /// Interaction logic for CPDFSignControl.xaml
  31. /// </summary>
  32. public partial class FillDigitalSignatureControl : UserControl
  33. {
  34. private readonly string logoPath = "Logo_opa40.png";
  35. private string imagePath = string.Empty;
  36. private string Text = string.Empty;
  37. private Dictionary<string, Border> TabDict { get; set; }
  38. private CPDFSignatureConfig tempSignatureConfig = new CPDFSignatureConfig();
  39. private CPDFSignatureCertificate signatureCertificate;
  40. public CPDFDocument Document;
  41. private string signatureName = string.Empty;
  42. private string location = string.Empty;
  43. private string reason = string.Empty;
  44. private float[] textColor = new float[] { 0, 0, 0 };
  45. private string _signaturePath = string.Empty;
  46. public string SignaturePath
  47. {
  48. get => _signaturePath;
  49. set
  50. {
  51. _signaturePath = value;
  52. }
  53. }
  54. private string _password = string.Empty;
  55. public string Password
  56. {
  57. get => _password;
  58. set
  59. {
  60. _password = value;
  61. signatureCertificate = CPDFPKCS12CertHelper.GetCertificateWithPKCS12Path(SignaturePath, Password);
  62. signatureName = DictionaryValueConverter.GetGrantorFromDictionary(signatureCertificate.SubjectDict);
  63. tempSignatureConfig.Text = signatureName;
  64. InitTempSignature();
  65. }
  66. }
  67. private void InitTempSignature()
  68. {
  69. NameChk.IsChecked = true;
  70. DateChk.IsChecked = true;
  71. LogoChk.IsChecked = true;
  72. TabChk.IsChecked = true;
  73. SetProperty();
  74. CreateTempSignature();
  75. KeyboardInPutTextBox.Text = signatureName;
  76. }
  77. public CPDFSignatureWidget signatureWidget { get; set; }
  78. public event EventHandler<string> AfterFillSignature;
  79. public FillDigitalSignatureControl()
  80. {
  81. InitializeComponent();
  82. TabDict = new Dictionary<string, Border>
  83. {
  84. ["Keyboard"] = KeyboardBorder,
  85. ["Trackpad"] = TrackpadBorder,
  86. ["Image"] = ImageBorder,
  87. ["None"] = NoneBorder
  88. };
  89. SetCheckedTab("Keyboard");
  90. ReasonCmb.SelectedIndex = 0;
  91. }
  92. private void CreateTempSignature()
  93. {
  94. CPDFDocument tempDocument = CPDFDocument.CreateDocument();
  95. tempDocument.InsertPage(0, 200, 200, string.Empty);
  96. CPDFPage page = tempDocument.PageAtIndex(0);
  97. CPDFSignatureWidget signatureWidget = page.CreateWidget(C_WIDGET_TYPE.WIDGET_SIGNATUREFIELDS) as CPDFSignatureWidget;
  98. signatureWidget.SetRect(new CRect(0, 100, 300, 0));
  99. tempSignatureConfig.IsDrawLogo = (bool)LogoChk.IsChecked;
  100. if (tempSignatureConfig.IsDrawLogo)
  101. {
  102. if(!string.IsNullOrEmpty(logoPath))
  103. {
  104. byte[] imageData = null;
  105. int imageWidth = 0;
  106. int imageHeight = 0;
  107. ComPDFKit.Tool.Help.PDFHelp.ImagePathToByte(logoPath, ref imageData, ref imageWidth, ref imageHeight);
  108. if (imageData != null && imageWidth > 0 && imageHeight > 0)
  109. {
  110. if (signatureWidget.IsValid())
  111. {
  112. tempSignatureConfig.LogoData = imageData;
  113. tempSignatureConfig.LogoWidth = imageWidth;
  114. tempSignatureConfig.LogoHeight = imageHeight;
  115. }
  116. }
  117. }
  118. }
  119. tempSignatureConfig.Content = Text;
  120. tempSignatureConfig.TextColor = textColor;
  121. tempSignatureConfig.ContentColor = new float[] { 0, 0, 0 };
  122. signatureWidget.UpdataApWithSignature(tempSignatureConfig);
  123. byte[] signatureBitmapBytes = GetTempSignatureImage(signatureWidget, out int width, out int height);
  124. signatureWidget.ReleaseAnnot();
  125. if (signatureBitmapBytes.Length > 0)
  126. {
  127. PixelFormat fmt = PixelFormats.Bgra32;
  128. BitmapSource bps = BitmapSource.Create(width, height, 96, 96, fmt, null, signatureBitmapBytes, (width * fmt.BitsPerPixel + 7) / 8);
  129. imageControl.Source = bps;
  130. }
  131. else
  132. {
  133. imageControl.Source = null;
  134. }
  135. }
  136. public static byte[] GetTempSignatureImage(CPDFSignatureWidget signatureWidget, out int width, out int height)
  137. {
  138. CRect rect = signatureWidget.GetRect();
  139. var flags = BindingFlags.NonPublic | BindingFlags.Static;
  140. var dpiProperty = typeof(SystemParameters).GetProperty("Dpi", flags);
  141. int dpi = (int)dpiProperty.GetValue(null, null);
  142. width = (int)(rect.width() * dpi / 72D * 2);
  143. height = (int)(rect.height() * dpi / 72D * 2);
  144. byte[] imageData = new byte[width * height * 4];
  145. signatureWidget.RenderAnnot(width, height, imageData, CPDFAppearanceType.Normal);
  146. return imageData;
  147. }
  148. private void TextAlignBtn_Click(object sender, RoutedEventArgs e)
  149. {
  150. ToggleButton checkBtn = sender as ToggleButton;
  151. if (checkBtn == null)
  152. {
  153. return;
  154. }
  155. checkBtn.IsChecked = true;
  156. if (checkBtn != TextAlignLeftBtn)
  157. {
  158. tempSignatureConfig.IsContentAlignLeft = true;
  159. TextAlignLeftBtn.IsChecked = false;
  160. }
  161. if (checkBtn != TextAlignRightBtn)
  162. {
  163. tempSignatureConfig.IsContentAlignLeft = false;
  164. TextAlignRightBtn.IsChecked = false;
  165. }
  166. CreateTempSignature();
  167. }
  168. private void Border_MouseDown(object sender, MouseButtonEventArgs e)
  169. {
  170. Border clickBorder = sender as Border;
  171. if (clickBorder == null || clickBorder.Tag == null)
  172. {
  173. return;
  174. }
  175. SetCheckedTab(clickBorder.Tag.ToString());
  176. ImagePickPanel.Visibility = Visibility.Hidden;
  177. if (clickBorder == NoneBorder)
  178. {
  179. tempSignatureConfig.IsDrawOnlyContent = true;
  180. }
  181. else
  182. {
  183. tempSignatureConfig.IsDrawOnlyContent = false;
  184. if (clickBorder == KeyboardBorder)
  185. {
  186. tempSignatureConfig.Text = signatureName;
  187. //tempSignatureConfig.ImageBitmap = null;
  188. KeyboardPopup.Visibility = Visibility.Visible;
  189. }
  190. else
  191. {
  192. tempSignatureConfig.Text = string.Empty;
  193. if (clickBorder == TrackpadBorder)
  194. {
  195. CanvaDrawPopup.Visibility = Visibility.Visible;
  196. }
  197. else if (clickBorder == ImageBorder)
  198. {
  199. ImagePickPanel.Visibility = Visibility.Visible;
  200. if (!string.IsNullOrEmpty(imagePath))
  201. {
  202. byte[] imageData = null;
  203. int imageWidth = 0;
  204. int imageHeight = 0;
  205. ComPDFKit.Tool.Help.PDFHelp.ImagePathToByte(imagePath, ref imageData, ref imageWidth, ref imageHeight);
  206. if (imageData != null && imageWidth > 0 && imageHeight > 0)
  207. {
  208. if (signatureWidget.IsValid())
  209. {
  210. tempSignatureConfig.ImageData = imageData;
  211. tempSignatureConfig.ImageWidth = imageWidth;
  212. tempSignatureConfig.ImageHeight = imageHeight;
  213. }
  214. }
  215. }
  216. }
  217. }
  218. }
  219. SetProperty();
  220. CreateTempSignature();
  221. }
  222. private void SetCheckedTab(string tab)
  223. {
  224. if (TabDict != null && TabDict.ContainsKey(tab))
  225. {
  226. foreach (string key in TabDict.Keys)
  227. {
  228. Border checkBorder = TabDict[key];
  229. if (checkBorder == null)
  230. {
  231. continue;
  232. }
  233. checkBorder.BorderThickness = new Thickness(0);
  234. if (key == tab)
  235. {
  236. checkBorder.BorderThickness = new Thickness(0, 0, 0, 2);
  237. }
  238. }
  239. }
  240. }
  241. private void CanvasPopupClose_Click(object sender, RoutedEventArgs e)
  242. {
  243. CanvaDrawPopup.Visibility = Visibility.Collapsed;
  244. }
  245. private void CanvasClearBtn_Click(object sender, RoutedEventArgs e)
  246. {
  247. DrawInkCanvas.Strokes.Clear();
  248. }
  249. private void CanvasPopupConfirm_Click(object sender, RoutedEventArgs e)
  250. {
  251. int height = 0;
  252. int width = 0;
  253. tempSignatureConfig.ImageData = GetDrawInk(ref height,ref width);
  254. tempSignatureConfig.ImageWidth = width;
  255. tempSignatureConfig.ImageHeight = height;
  256. CanvaDrawPopup.Visibility = Visibility.Collapsed;
  257. SetProperty();
  258. CreateTempSignature();
  259. }
  260. public byte[] GetDrawInk(ref int height, ref int width)
  261. {
  262. if (DrawInkCanvas != null && DrawInkCanvas.Strokes != null && DrawInkCanvas.Strokes.Count > 0)
  263. {
  264. Rect bound = DrawInkCanvas.Strokes.GetBounds();
  265. DrawingVisual drawVisual = new DrawingVisual();
  266. DrawingContext drawContext = drawVisual.RenderOpen();
  267. foreach (Stroke drawStroke in DrawInkCanvas.Strokes)
  268. {
  269. Pen drawPen = new Pen(new SolidColorBrush(drawStroke.DrawingAttributes.Color), drawStroke.DrawingAttributes.Width);
  270. PathGeometry drawPath = new PathGeometry();
  271. PathFigureCollection Figures = new PathFigureCollection();
  272. PathFigure AddFigure = new PathFigure();
  273. Figures.Add(AddFigure);
  274. drawPath.Figures = Figures;
  275. if (drawStroke.StylusPoints.Count > 1)
  276. {
  277. StylusPoint startPoint = drawStroke.StylusPoints[0];
  278. AddFigure.StartPoint = new Point(startPoint.X - bound.X, startPoint.Y - bound.Y);
  279. for (int i = 1; i < drawStroke.StylusPoints.Count; i++)
  280. {
  281. StylusPoint drawPoint = drawStroke.StylusPoints[i];
  282. Point offsetPoint = new Point(drawPoint.X - bound.X, drawPoint.Y - bound.Y);
  283. LineSegment drawSegment = new LineSegment();
  284. drawSegment.Point = offsetPoint;
  285. AddFigure.Segments.Add(drawSegment);
  286. }
  287. }
  288. if (AddFigure.Segments.Count > 0)
  289. {
  290. drawContext.DrawGeometry(null, drawPen, drawPath);
  291. }
  292. }
  293. drawContext.Close();
  294. RenderTargetBitmap renderBitmap = new RenderTargetBitmap((int)bound.Width, (int)bound.Height, 96, 96, PixelFormats.Pbgra32);
  295. renderBitmap.Render(drawVisual);
  296. BitmapFrame newFrame = BitmapFrame.Create(renderBitmap);
  297. PngBitmapEncoder pngEncoder = new PngBitmapEncoder();
  298. pngEncoder.Frames.Add(newFrame);
  299. using (MemoryStream newStream = new MemoryStream())
  300. {
  301. pngEncoder.Save(newStream);
  302. Bitmap bitmap = new Bitmap(newStream);
  303. height = bitmap.Height;
  304. width = bitmap.Width;
  305. return GetBitmapData(bitmap);
  306. }
  307. }
  308. else
  309. {
  310. return null;
  311. }
  312. }
  313. private byte[] GetBitmapData(Bitmap bitmap)
  314. {
  315. // Lock the bitmap's bits.
  316. Rectangle rect = new Rectangle(0, 0, bitmap.Width, bitmap.Height);
  317. BitmapData bmpData = bitmap.LockBits(rect, ImageLockMode.ReadWrite, bitmap.PixelFormat);
  318. // Get the address of the first line.
  319. IntPtr ptr = bmpData.Scan0;
  320. // Declare an array to hold the bytes of the bitmap.
  321. int bytes = Math.Abs(bmpData.Stride) * bitmap.Height;
  322. byte[] rgbValues = new byte[bytes];
  323. // Copy the RGB values into the array.
  324. System.Runtime.InteropServices.Marshal.Copy(ptr, rgbValues, 0, bytes);
  325. // Unlock the bits.
  326. bitmap.UnlockBits(bmpData);
  327. return rgbValues;
  328. }
  329. private void SetProperty()
  330. {
  331. Text = string.Empty;
  332. if ((bool)NameChk.IsChecked)
  333. {
  334. if ((bool)TabChk.IsChecked)
  335. {
  336. Text += "Name: ";
  337. }
  338. Text += DictionaryValueConverter.GetGrantorFromDictionary(signatureCertificate.SubjectDict) + "\n";
  339. }
  340. if ((bool)DateChk.IsChecked)
  341. {
  342. if ((bool)TabChk.IsChecked)
  343. {
  344. Text += "Date: ";
  345. }
  346. DateTime currentDateTime = DateTime.Now;
  347. string customFormat = "yyyy.MM.dd HH:mm:ss";
  348. string formattedDateTime = currentDateTime.ToString(customFormat);
  349. Text += formattedDateTime + "\n";
  350. }
  351. if ((bool)LogoChk.IsChecked)
  352. {
  353. tempSignatureConfig.IsDrawLogo = true;
  354. }
  355. else
  356. {
  357. tempSignatureConfig.IsDrawLogo = false;
  358. }
  359. if ((bool)ReasonChk.IsChecked)
  360. {
  361. if ((bool)TabChk.IsChecked)
  362. {
  363. Text += "Reason: ";
  364. }
  365. Text += (ReasonCmb.SelectedItem as ComboBoxItem).Content.ToString() + "\n";
  366. }
  367. if ((bool)DistinguishableNameChk.IsChecked)
  368. {
  369. if ((bool)TabChk.IsChecked)
  370. {
  371. Text += "DN: ";
  372. }
  373. var keyOrder = new List<string> { "CN", "O", "OU", "emailAddress", "L", "ST", "C" };
  374. var keyMapping = new Dictionary<string, string>
  375. {
  376. { "CN", "cn" },
  377. { "OU", "ou" },
  378. { "O", "o" },
  379. { "L", "l" },
  380. { "ST", "st" },
  381. { "C", "c" },
  382. { "emailAddress", "email" }
  383. };
  384. var stringBuilder = new StringBuilder();
  385. foreach (var originalKey in keyOrder)
  386. {
  387. if (keyMapping.TryGetValue(originalKey, out string newKey) &&
  388. signatureCertificate.SubjectDict.TryGetValue(originalKey, out string value) && !string.IsNullOrEmpty(value))
  389. {
  390. if (stringBuilder.Length > 0)
  391. {
  392. stringBuilder.Append(",");
  393. }
  394. stringBuilder.Append(newKey + "=" + value);
  395. }
  396. }
  397. Text += stringBuilder.ToString()+"\n";
  398. }
  399. if ((bool)ComPDFKitVersionChk.IsChecked)
  400. {
  401. Assembly assembly = Assembly.GetExecutingAssembly();
  402. Version version = assembly.GetName().Version;
  403. if ((bool)TabChk.IsChecked)
  404. {
  405. Text += "ComPDFKit Version: ";
  406. }
  407. Text += version.Major.ToString() + "." + version.Minor.ToString() + "." + version.Build.ToString() + "." + version.Revision.ToString() + "\n";
  408. }
  409. if ((bool)PositionChk.IsChecked)
  410. {
  411. if ((bool)TabChk.IsChecked)
  412. {
  413. Text += "Position: ";
  414. }
  415. Text += PositionTbx.Text + "\n";
  416. }
  417. }
  418. private void ReasonCheckBox_Click(object sender, RoutedEventArgs e)
  419. {
  420. CheckBox checkItem = sender as CheckBox;
  421. if (checkItem == null)
  422. {
  423. return;
  424. }
  425. ReasonPanel.Visibility = checkItem.IsChecked == true ? Visibility.Visible : Visibility.Collapsed;
  426. }
  427. private void BrowseTxt_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  428. {
  429. string filter = "Image files (*.jpg, *.jpeg, *.png, *.bmp)|*.jpg;*.jpeg;*.png;*.bmp";
  430. string pngPath = CommonHelper.GetExistedPathOrEmpty(filter);
  431. if (!string.IsNullOrEmpty(pngPath))
  432. {
  433. try
  434. {
  435. byte[] imageData = null;
  436. int imageWidth = 0;
  437. int imageHeight = 0;
  438. ComPDFKit.Tool.Help.PDFHelp.ImagePathToByte(pngPath, ref imageData, ref imageWidth, ref imageHeight);
  439. if (imageData != null && imageWidth > 0 && imageHeight > 0)
  440. {
  441. tempSignatureConfig.ImageData = imageData;
  442. tempSignatureConfig.ImageWidth = imageWidth;
  443. tempSignatureConfig.ImageHeight = imageHeight;
  444. }
  445. }
  446. catch (Exception exception)
  447. {
  448. MessageBox.Show("The image is invalid.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
  449. return;
  450. }
  451. SetProperty();
  452. CreateTempSignature();
  453. }
  454. }
  455. private void ClearTxt_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  456. {
  457. imagePath = string.Empty;
  458. //tempSignatureConfig.ImageBitmap = null;
  459. SetProperty();
  460. CreateTempSignature();
  461. }
  462. private void NameChk_Click(object sender, RoutedEventArgs e)
  463. {
  464. SetProperty();
  465. CreateTempSignature();
  466. }
  467. private void DateChk_Click(object sender, RoutedEventArgs e)
  468. {
  469. SetProperty();
  470. CreateTempSignature();
  471. }
  472. private void LogoChk_Click(object sender, RoutedEventArgs e)
  473. {
  474. SetProperty();
  475. CreateTempSignature();
  476. }
  477. private void ReasonChk_Click(object sender, RoutedEventArgs e)
  478. {
  479. if (!(bool)ReasonChk.IsChecked)
  480. {
  481. Reasonstp.Visibility = Visibility.Collapsed;
  482. }
  483. else
  484. {
  485. Reasonstp.Visibility = Visibility.Visible;
  486. }
  487. SetProperty();
  488. CreateTempSignature();
  489. }
  490. private void DistinguishableNameChk_Click(object sender, RoutedEventArgs e)
  491. {
  492. SetProperty();
  493. CreateTempSignature();
  494. }
  495. private void PositionChk_Click(object sender, RoutedEventArgs e)
  496. {
  497. if (!(bool)PositionChk.IsChecked)
  498. {
  499. PositionStp.Visibility = Visibility.Collapsed;
  500. }
  501. else
  502. {
  503. PositionStp.Visibility = Visibility.Visible;
  504. }
  505. SetProperty();
  506. CreateTempSignature();
  507. }
  508. private void TabChk_Click(object sender, RoutedEventArgs e)
  509. {
  510. SetProperty();
  511. CreateTempSignature();
  512. }
  513. private void ReasonCmb_SelectionChanged(object sender, SelectionChangedEventArgs e)
  514. {
  515. SetProperty();
  516. CreateTempSignature();
  517. }
  518. private void ComPDFKitVersionChk_Click(object sender, RoutedEventArgs e)
  519. {
  520. SetProperty();
  521. CreateTempSignature();
  522. }
  523. private void PositionTbx_TextChanged(object sender, TextChangedEventArgs e)
  524. {
  525. if (!(bool)PositionChk.IsChecked)
  526. {
  527. PositionStp.Visibility = Visibility.Collapsed;
  528. }
  529. else
  530. {
  531. PositionStp.Visibility = Visibility.Visible;
  532. }
  533. SetProperty();
  534. CreateTempSignature();
  535. }
  536. private void ContinueBtn_Click(object sender, RoutedEventArgs e)
  537. {
  538. string filePath = CommonHelper.GetGeneratePathOrEmpty("PDF files (*.pdf)|*.pdf", Document.FileName + "_Signed.pdf");
  539. if (string.IsNullOrEmpty(filePath))
  540. {
  541. return;
  542. }
  543. if (filePath.ToLower() == Document.FilePath.ToLower())
  544. {
  545. MessageBox.Show("Do not use the new file name that is the same as the current file name.");
  546. return;
  547. }
  548. if ((bool)ReasonChk.IsChecked)
  549. {
  550. reason = (ReasonCmb?.SelectedItem as ComboBoxItem)?.Content?.ToString();
  551. }
  552. else
  553. {
  554. reason = string.Empty;
  555. }
  556. if ((bool)PositionChk.IsChecked)
  557. {
  558. location = PositionTbx.Text;
  559. }
  560. else
  561. {
  562. location = string.Empty;
  563. }
  564. signatureWidget.UpdataApWithSignature(tempSignatureConfig);
  565. if (Document.WriteSignatureToFilePath(signatureWidget, filePath, SignaturePath, Password, location, reason, CPDFSignaturePermissions.CPDFSignaturePermissionsNone))
  566. {
  567. signatureCertificate.AddToTrustedCertificates();
  568. AfterFillSignature?.Invoke(sender, filePath);
  569. }
  570. CloseWindow(sender);
  571. }
  572. private void CancelBtn_Click(object sender, RoutedEventArgs e)
  573. {
  574. CloseWindow(sender);
  575. }
  576. private void CloseWindow(object sender)
  577. {
  578. Window parentWindow = Window.GetWindow(sender as DependencyObject);
  579. parentWindow?.Close();
  580. }
  581. private void TextColorPickerControl_Loaded(object sender, RoutedEventArgs e)
  582. {
  583. TextColorPickerControl.SetIsChecked(0);
  584. TextColorPickerControl.Brush = new SolidColorBrush(Colors.Black);
  585. }
  586. private void TextColorPickerControl_ColorChanged(object sender, EventArgs e)
  587. {
  588. KeyboardInPutTextBox.Foreground = TextColorPickerControl.Brush;
  589. }
  590. private void KeyboardCancel_Click(object sender, RoutedEventArgs e)
  591. {
  592. KeyboardPopup.Visibility = Visibility.Collapsed;
  593. }
  594. private void KeyboardClear_Click(object sender, RoutedEventArgs e)
  595. {
  596. KeyboardInPutTextBox.Text = string.Empty;
  597. }
  598. private void KeyboardSave_Click(object sender, RoutedEventArgs e)
  599. {
  600. signatureName = KeyboardInPutTextBox.Text;
  601. tempSignatureConfig.Text = signatureName;
  602. SolidColorBrush solidColorBrush = TextColorPickerControl.Brush as SolidColorBrush;
  603. float red = solidColorBrush.Color.R;
  604. float green = solidColorBrush.Color.G;
  605. float blue = solidColorBrush.Color.B;
  606. textColor = new[] { red / 255, green / 255, blue / 255 };
  607. KeyboardPopup.Visibility = Visibility.Collapsed;
  608. SetProperty();
  609. CreateTempSignature();
  610. }
  611. private void KeyboardPopupClose_Click(object sender, RoutedEventArgs e)
  612. {
  613. KeyboardPopup.Visibility = Visibility.Collapsed;
  614. }
  615. }
  616. }