RadioButtonProperty.xaml.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. using ComPDFKit.PDFAnnotation.Form;
  2. using ComPDFKit.PDFAnnotation;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Media;
  9. using ComPDFKit.PDFDocument;
  10. using ComPDFKit.Tool;
  11. using ComPDFKit.Tool.Help;
  12. namespace Compdfkit_Tools.PDFControl
  13. {
  14. public partial class RadioButtonProperty : UserControl
  15. {
  16. private RadioButtonParam widgetParam = null;
  17. private CPDFRadioButtonWidget cPDFAnnotation = null;
  18. private PDFViewControl pdfViewerControl = null;
  19. private CPDFDocument cPDFDocument = null;
  20. bool IsLoadedData = false;
  21. public RadioButtonProperty()
  22. {
  23. InitializeComponent();
  24. }
  25. #region Loaded
  26. public void SetProperty(AnnotParam annotParam, CPDFAnnotation annotation, CPDFDocument doc, PDFViewControl cPDFViewer)
  27. {
  28. widgetParam = (RadioButtonParam)annotParam;
  29. cPDFAnnotation = (CPDFRadioButtonWidget)annotation;
  30. pdfViewerControl = cPDFViewer;
  31. cPDFDocument = doc;
  32. }
  33. private void UserControl_Loaded(object sender, RoutedEventArgs e)
  34. {
  35. FieldNameText.Text = widgetParam.FieldName;
  36. FormFieldCombox.SelectedIndex = (int)ParamConverter.ConverterWidgetFormFlags(widgetParam.Flags, widgetParam.IsHidden);
  37. BorderColorPickerControl.SetCheckedForColor(ParamConverter.ConverterByteForColor(widgetParam.LineColor));
  38. BackgroundColorPickerControl.SetCheckedForColor(ParamConverter.ConverterByteForColor(widgetParam.BgColor));
  39. RadioButtonStyleCombox.SelectedIndex = (int)widgetParam.CheckStyle;
  40. chkSelected.IsChecked = widgetParam.IsChecked;
  41. if (IsShowWarning())
  42. {
  43. WarningPanel.Visibility = Visibility.Collapsed;
  44. }
  45. else
  46. {
  47. WarningPanel.Visibility = Visibility.Visible;
  48. }
  49. IsLoadedData = true;
  50. }
  51. private bool IsShowWarning()
  52. {
  53. int count = 0;
  54. var page = cPDFDocument.PageAtIndex(pdfViewerControl.PDFViewTool.GetCPDFViewer().CurrentRenderFrame.PageIndex);
  55. List<CPDFAnnotation> annotList = page.GetAnnotations();
  56. if (annotList != null && annotList.Count > 0)
  57. {
  58. count = annotList.Where(x => x.Type == C_ANNOTATION_TYPE.C_ANNOTATION_WIDGET)
  59. .Cast<CPDFWidget>().Where(x => x.WidgeType == C_WIDGET_TYPE.WIDGET_RADIOBUTTON).Count();
  60. }
  61. return count>1;
  62. }
  63. private void UserControl_Unloaded(object sender, RoutedEventArgs e)
  64. {
  65. IsLoadedData = false;
  66. }
  67. #endregion
  68. private void FieldNameText_TextChanged(object sender, TextChangedEventArgs e)
  69. {
  70. if (IsLoadedData)
  71. {
  72. cPDFAnnotation.SetFieldName((sender as TextBox).Text);
  73. pdfViewerControl.PDFViewTool.GetCPDFViewer().UpDateAnnotFrame();
  74. }
  75. }
  76. private void FormFieldCombox_SelectionChanged(object sender, SelectionChangedEventArgs e)
  77. {
  78. if (IsLoadedData)
  79. {
  80. cPDFAnnotation.SetFlags(ParamConverter.GetFormFlags((ParamConverter.FormField)(sender as ComboBox).SelectedIndex, cPDFAnnotation));
  81. pdfViewerControl.PDFViewTool.GetCPDFViewer().UpDateAnnotFrame();
  82. }
  83. }
  84. private void BorderColorPickerControl_ColorChanged(object sender, EventArgs e)
  85. {
  86. if (IsLoadedData)
  87. {
  88. byte[] Color = new byte[3];
  89. Color[0] = ((SolidColorBrush)BorderColorPickerControl.Brush).Color.R;
  90. Color[1] = ((SolidColorBrush)BorderColorPickerControl.Brush).Color.G;
  91. Color[2] = ((SolidColorBrush)BorderColorPickerControl.Brush).Color.B;
  92. cPDFAnnotation.SetWidgetBorderRGBColor(Color);
  93. pdfViewerControl.PDFViewTool.GetCPDFViewer().UpDateAnnotFrame();
  94. }
  95. }
  96. private void BackgroundColorPickerControl_ColorChanged(object sender, EventArgs e)
  97. {
  98. if (IsLoadedData)
  99. {
  100. byte[] Color = new byte[3];
  101. Color[0] = ((SolidColorBrush)BackgroundColorPickerControl.Brush).Color.R;
  102. Color[1] = ((SolidColorBrush)BackgroundColorPickerControl.Brush).Color.G;
  103. Color[2] = ((SolidColorBrush)BackgroundColorPickerControl.Brush).Color.B;
  104. cPDFAnnotation.SetWidgetBgRGBColor(Color);
  105. pdfViewerControl.PDFViewTool.GetCPDFViewer().UpDateAnnotFrame();
  106. }
  107. }
  108. private void RadioButtonStyleCombox_SelectionChanged(object sender, SelectionChangedEventArgs e)
  109. {
  110. if (IsLoadedData)
  111. {
  112. cPDFAnnotation.SetWidgetCheckStyle((C_CHECK_STYLE)(sender as ComboBox).SelectedIndex);
  113. pdfViewerControl.PDFViewTool.GetCPDFViewer().UpDateAnnotFrame();
  114. }
  115. }
  116. private void chkSelected_Checked(object sender, RoutedEventArgs e)
  117. {
  118. if (IsLoadedData)
  119. {
  120. cPDFAnnotation.SetChecked(true);
  121. pdfViewerControl.PDFViewTool.GetCPDFViewer().UpDateAnnotFrame();
  122. }
  123. }
  124. private void chkSelected_Unchecked(object sender, RoutedEventArgs e)
  125. {
  126. if (IsLoadedData)
  127. {
  128. cPDFAnnotation.SetChecked(false);
  129. pdfViewerControl.PDFViewTool.GetCPDFViewer().UpDateAnnotFrame();
  130. }
  131. }
  132. }
  133. }