GlobalColorPickerWindow.xaml.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. using GeekDesk.Interface;
  2. using System;
  3. using System.Threading;
  4. using System.Windows;
  5. using System.Windows.Controls;
  6. using System.Windows.Input;
  7. using System.Windows.Media;
  8. namespace GeekDesk.Control.Windows
  9. {
  10. /// <summary>
  11. /// GlobalColorPickerWindow.xaml 的交互逻辑
  12. /// </summary>
  13. public partial class GlobalColorPickerWindow : IWindowCommon
  14. {
  15. PixelColorPickerWindow colorPickerWindow = null;
  16. public GlobalColorPickerWindow()
  17. {
  18. this.Topmost = true;
  19. InitializeComponent();
  20. }
  21. public void OnKeyDown(object sender, KeyEventArgs e)
  22. {
  23. if (e.Key == Key.Escape)
  24. {
  25. this.DataContext = null;
  26. this.Close();
  27. }
  28. }
  29. /// <summary>
  30. /// 取消按钮事件
  31. /// </summary>
  32. /// <param name="sender"></param>
  33. /// <param name="e"></param>
  34. private void MyColorPicker_Canceled(object sender, EventArgs e)
  35. {
  36. MyColorPickerClose();
  37. }
  38. private void MyColorPicker_Confirmed(object sender, HandyControl.Data.FunctionEventArgs<Color> e)
  39. {
  40. Color c = MyColorPicker.SelectedBrush.Color;
  41. Clipboard.SetData(DataFormats.Text, string.Format("#{0:X2}{1:X2}{2:X2}{3:X2}", c.A, c.R, c.G, c.B));
  42. }
  43. /// <summary>
  44. /// 移动窗口
  45. /// </summary>
  46. /// <param name="sender"></param>
  47. /// <param name="e"></param>
  48. private void DragMove(object sender, System.Windows.Input.MouseButtonEventArgs e)
  49. {
  50. if (e.LeftButton == MouseButtonState.Pressed)
  51. {
  52. this.DragMove();
  53. }
  54. }
  55. private void MyColorPicker_Checked(object sender, RoutedEventArgs e)
  56. {
  57. this.Hide();
  58. if (colorPickerWindow == null || !colorPickerWindow.Activate())
  59. {
  60. colorPickerWindow = new PixelColorPickerWindow(MyColorPicker);
  61. }
  62. colorPickerWindow.Show();
  63. }
  64. private void MyColorPickerClose()
  65. {
  66. this.Close();
  67. }
  68. private static System.Windows.Window window = null;
  69. public static void CreateNoShow()
  70. {
  71. if (window == null || !window.Activate())
  72. {
  73. window = new GlobalColorPickerWindow();
  74. window.Show();
  75. }
  76. window.Hide();
  77. GlobalColorPickerWindow thisWindow = (GlobalColorPickerWindow)window;
  78. if (thisWindow.colorPickerWindow == null || !thisWindow.colorPickerWindow.Activate())
  79. {
  80. thisWindow.colorPickerWindow = new PixelColorPickerWindow(thisWindow.MyColorPicker);
  81. }
  82. thisWindow.colorPickerWindow.Show();
  83. }
  84. public static void Show()
  85. {
  86. if (window == null || !window.Activate())
  87. {
  88. window = new GlobalColorPickerWindow();
  89. }
  90. window.Show();
  91. Keyboard.Focus(window);
  92. }
  93. public static void ShowOrHide()
  94. {
  95. if (window == null || !window.Activate())
  96. {
  97. window = new GlobalColorPickerWindow();
  98. window.Show();
  99. Keyboard.Focus(window);
  100. }
  101. else
  102. {
  103. window.Close();
  104. }
  105. }
  106. private void MyColorPicker_SelectedColorChanged(object sender, HandyControl.Data.FunctionEventArgs<Color> e)
  107. {
  108. Show();
  109. }
  110. private void Button_MouseEnter(object sender, MouseEventArgs e)
  111. {
  112. Button btn = sender as Button;
  113. btn.Opacity = 1;
  114. }
  115. private void Button_MouseLeave(object sender, MouseEventArgs e)
  116. {
  117. Button btn = sender as Button;
  118. btn.Opacity = 0.6;
  119. }
  120. private void Button_Click(object sender, RoutedEventArgs e)
  121. {
  122. this.Close();
  123. }
  124. }
  125. }