|
- using System;
- using System.Collections.Generic;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Controls;
- using System.Windows.Media;
- using System.Windows.Shapes;
- using System.Windows;
-
- namespace BPASmartClient.CustomResource.UserControls
- {
- public class WpfUtils
- {
- public static Line DrawLine(Canvas canvas, double x1, double y1, double x2, double y2, System.Windows.Media.Brush brush, double thickness)
- {
- Line line = new Line();
- line.X1 = x1;
- line.Y1 = y1;
- line.X2 = x2;
- line.Y2 = y2;
- line.StrokeThickness = thickness;
- line.Stroke = brush;
- canvas.Children.Add(line);
- return line;
- }
-
- public static System.Windows.Shapes.Rectangle FillRectangle(Canvas canvas, double x, double y, double width, double height, System.Windows.Media.Color color)
- {
- return FillRectangle(canvas, x, y, width, height, new SolidColorBrush(color));
- }
-
- public static System.Windows.Shapes.Rectangle FillRectangle(Canvas canvas, double x, double y, double width, double height, System.Windows.Media.Brush brush)
- {
- if (width >= 0.0 && height >= 0.0)
- {
- System.Windows.Shapes.Rectangle rectangle = new System.Windows.Shapes.Rectangle();
- rectangle.Width = width;
- rectangle.Height = height;
- canvas.Children.Add(rectangle);
- Canvas.SetLeft(rectangle, x);
- Canvas.SetTop(rectangle, y);
- rectangle.Fill = brush;
- return rectangle;
- }
- return null;
- }
-
-
- public static Ellipse FillEllipse(Canvas canvas, double x, double y, double width, double height, System.Windows.Media.Color color)
- {
- return FillEllipse(canvas, x, y, width, height, new SolidColorBrush(color));
- }
-
- public static Ellipse FillEllipse(Canvas canvas, double x, double y, double width, double height, System.Windows.Media.Brush brush)
- {
- Ellipse ellipse = new Ellipse();
- ellipse.Width = width;
- ellipse.Height = height;
- canvas.Children.Add(ellipse);
- Canvas.SetLeft(ellipse, x);
- Canvas.SetTop(ellipse, y);
- ellipse.Fill = brush;
- return ellipse;
- }
-
- public static Ellipse FillEllipse(Canvas canvas, RectangleF rectangle, System.Windows.Media.Brush brush)
- {
- return FillEllipse(canvas, rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height, brush);
- }
-
- public static void DrawString(Canvas canvas, string text, System.Windows.Media.Brush brush, RectangleF rectangle, HorizontalAlignment horizontal, VerticalAlignment vertical)
- {
- DrawString(canvas, text, brush, rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height, horizontal, vertical);
- }
-
- 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)
- {
- Label label = new Label();
- label.Width = width;
- label.Height = height;
- label.Foreground = foreground;
- label.HorizontalContentAlignment = horizontal;
- label.VerticalContentAlignment = vertical;
- label.Content = text;
- canvas.Children.Add(label);
- Canvas.SetLeft(label, x);
- Canvas.SetTop(label, y);
- }
-
- }
- }
|