CPDFTextAlignUI.xaml.cs 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. using ComPDFKit.PDFPage.Edit;
  2. using System;
  3. using System.Windows;
  4. using System.Windows.Controls;
  5. using System.Windows.Controls.Primitives;
  6. using System.Windows.Media;
  7. namespace Compdfkit_Tools.Edit
  8. {
  9. public partial class CPDFTextAlignUI : UserControl
  10. {
  11. #region Property
  12. public event EventHandler<TextAlignType> TextAlignChanged;
  13. public TextAlignType Alignment { get; private set; }
  14. #endregion
  15. public CPDFTextAlignUI()
  16. {
  17. InitializeComponent();
  18. }
  19. #region Property changed
  20. public void SetFontAlign(TextAlignType newAlign)
  21. {
  22. ClearAlign();
  23. Alignment = newAlign;
  24. switch (newAlign)
  25. {
  26. case TextAlignType.AlignLeft:
  27. AlignLeftBtn.IsChecked = true;
  28. AlignLeftPath.Fill = Brushes.Blue;
  29. break;
  30. case TextAlignType.AlignMiddle:
  31. AlignCenterBtn.IsChecked = true;
  32. AlignCenterPath.Fill = Brushes.Blue;
  33. break;
  34. case TextAlignType.AlignRight:
  35. AlignRightBtn.IsChecked = true;
  36. AlignRightPath.Fill = Brushes.Blue;
  37. break;
  38. default:
  39. break;
  40. }
  41. }
  42. public void ClearAlign()
  43. {
  44. Alignment = TextAlignType.AlignNone;
  45. AlignLeftPath.Fill = Brushes.Gray;
  46. AlignCenterPath.Fill= Brushes.Gray;
  47. AlignRightPath.Fill= Brushes.Gray;
  48. AlignLeftBtn.IsChecked = false;
  49. AlignCenterBtn.IsChecked = false;
  50. AlignRightBtn.IsChecked= false;
  51. }
  52. private void TextAlignBtn_Click(object sender, RoutedEventArgs e)
  53. {
  54. ClearAlign();
  55. ToggleButton clickBtn = sender as ToggleButton;
  56. if (clickBtn != null && clickBtn.Tag!=null)
  57. {
  58. clickBtn.IsChecked = true;
  59. TextAlignType newAlign = Alignment;
  60. switch(clickBtn.Tag.ToString())
  61. {
  62. case "AlignLeft":
  63. newAlign = TextAlignType.AlignLeft;
  64. break;
  65. case "AlignCenter":
  66. newAlign = TextAlignType.AlignMiddle;
  67. break;
  68. case "AlignRight":
  69. newAlign= TextAlignType.AlignRight;
  70. break;
  71. default:
  72. break;
  73. }
  74. if(newAlign!=Alignment)
  75. {
  76. SetFontAlign(newAlign);
  77. TextAlignChanged?.Invoke(this, newAlign);
  78. }
  79. }
  80. }
  81. #endregion
  82. }
  83. }