CPDFTextAlignUI.xaml.cs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. public event EventHandler<TextAlignType> TextAlignChanged;
  12. public CPDFTextAlignUI()
  13. {
  14. InitializeComponent();
  15. }
  16. public TextAlignType Alignment { get;private set; }
  17. public void SetFontAlign(TextAlignType newAlign)
  18. {
  19. ClearAlign();
  20. Alignment = newAlign;
  21. switch (newAlign)
  22. {
  23. case TextAlignType.AlignLeft:
  24. AlignLeftBtn.IsChecked = true;
  25. AlignLeftPath.Fill = Brushes.Blue;
  26. break;
  27. case TextAlignType.AlignMiddle:
  28. AlignCenterBtn.IsChecked = true;
  29. AlignCenterPath.Fill = Brushes.Blue;
  30. break;
  31. case TextAlignType.AlignRight:
  32. AlignRightBtn.IsChecked = true;
  33. AlignRightPath.Fill = Brushes.Blue;
  34. break;
  35. default:
  36. break;
  37. }
  38. }
  39. public void ClearAlign()
  40. {
  41. Alignment = TextAlignType.AlignNone;
  42. AlignLeftPath.Fill = Brushes.Gray;
  43. AlignCenterPath.Fill= Brushes.Gray;
  44. AlignRightPath.Fill= Brushes.Gray;
  45. AlignLeftBtn.IsChecked = false;
  46. AlignCenterBtn.IsChecked = false;
  47. AlignRightBtn.IsChecked= false;
  48. }
  49. private void TextAlignBtn_Click(object sender, RoutedEventArgs e)
  50. {
  51. ClearAlign();
  52. ToggleButton clickBtn = sender as ToggleButton;
  53. if (clickBtn != null && clickBtn.Tag!=null)
  54. {
  55. clickBtn.IsChecked = true;
  56. TextAlignType newAlign = Alignment;
  57. switch(clickBtn.Tag.ToString())
  58. {
  59. case "AlignLeft":
  60. newAlign = TextAlignType.AlignLeft;
  61. break;
  62. case "AlignCenter":
  63. newAlign = TextAlignType.AlignMiddle;
  64. break;
  65. case "AlignRight":
  66. newAlign= TextAlignType.AlignRight;
  67. break;
  68. default:
  69. break;
  70. }
  71. if(newAlign!=Alignment)
  72. {
  73. SetFontAlign(newAlign);
  74. TextAlignChanged?.Invoke(this, newAlign);
  75. }
  76. }
  77. }
  78. }
  79. }