终端一体化运控平台
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 

94 lignes
3.6 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Drawing;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Windows.Controls;
  8. using System.Windows.Media;
  9. using System.Windows.Shapes;
  10. using System.Windows;
  11. namespace BPASmartClient.CustomResource.UserControls
  12. {
  13. public class WpfUtils
  14. {
  15. public static Line DrawLine(Canvas canvas, double x1, double y1, double x2, double y2, System.Windows.Media.Brush brush, double thickness)
  16. {
  17. Line line = new Line();
  18. line.X1 = x1;
  19. line.Y1 = y1;
  20. line.X2 = x2;
  21. line.Y2 = y2;
  22. line.StrokeThickness = thickness;
  23. line.Stroke = brush;
  24. canvas.Children.Add(line);
  25. return line;
  26. }
  27. public static System.Windows.Shapes.Rectangle FillRectangle(Canvas canvas, double x, double y, double width, double height, System.Windows.Media.Color color)
  28. {
  29. return FillRectangle(canvas, x, y, width, height, new SolidColorBrush(color));
  30. }
  31. public static System.Windows.Shapes.Rectangle FillRectangle(Canvas canvas, double x, double y, double width, double height, System.Windows.Media.Brush brush)
  32. {
  33. if (width >= 0.0 && height >= 0.0)
  34. {
  35. System.Windows.Shapes.Rectangle rectangle = new System.Windows.Shapes.Rectangle();
  36. rectangle.Width = width;
  37. rectangle.Height = height;
  38. canvas.Children.Add(rectangle);
  39. Canvas.SetLeft(rectangle, x);
  40. Canvas.SetTop(rectangle, y);
  41. rectangle.Fill = brush;
  42. return rectangle;
  43. }
  44. return null;
  45. }
  46. public static Ellipse FillEllipse(Canvas canvas, double x, double y, double width, double height, System.Windows.Media.Color color)
  47. {
  48. return FillEllipse(canvas, x, y, width, height, new SolidColorBrush(color));
  49. }
  50. public static Ellipse FillEllipse(Canvas canvas, double x, double y, double width, double height, System.Windows.Media.Brush brush)
  51. {
  52. Ellipse ellipse = new Ellipse();
  53. ellipse.Width = width;
  54. ellipse.Height = height;
  55. canvas.Children.Add(ellipse);
  56. Canvas.SetLeft(ellipse, x);
  57. Canvas.SetTop(ellipse, y);
  58. ellipse.Fill = brush;
  59. return ellipse;
  60. }
  61. public static Ellipse FillEllipse(Canvas canvas, RectangleF rectangle, System.Windows.Media.Brush brush)
  62. {
  63. return FillEllipse(canvas, rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height, brush);
  64. }
  65. public static void DrawString(Canvas canvas, string text, System.Windows.Media.Brush brush, RectangleF rectangle, HorizontalAlignment horizontal, VerticalAlignment vertical)
  66. {
  67. DrawString(canvas, text, brush, rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height, horizontal, vertical);
  68. }
  69. public static void DrawString(Canvas canvas, string text, System.Windows.Media.Brush foreground, double x, double y, double width, double height, HorizontalAlignment horizontal, VerticalAlignment vertical)
  70. {
  71. Label label = new Label();
  72. label.Width = width;
  73. label.Height = height;
  74. label.Foreground = foreground;
  75. label.HorizontalContentAlignment = horizontal;
  76. label.VerticalContentAlignment = vertical;
  77. label.Content = text;
  78. canvas.Children.Add(label);
  79. Canvas.SetLeft(label, x);
  80. Canvas.SetTop(label, y);
  81. }
  82. }
  83. }