首页 > 其他分享 >WPF Path LineGeometry,RectangleGeometry,EllipseGeometry

WPF Path LineGeometry,RectangleGeometry,EllipseGeometry

时间:2024-06-15 18:54:46浏览次数:23  
标签:actualHeight using System actualWidth new Path WPF RectangleGeometry

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WpfApp167
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            this.WindowState = WindowState.Maximized;
            this.Loaded += MainWindow_Loaded; 
        }

        private void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            Path rectPath = GenRectanglePath(this.ActualWidth, this.ActualHeight);
            this.gd.Children.Add(rectPath);
            Path gPath = GenLinePath(this.ActualWidth, this.ActualHeight);
            this.gd.Children.Add(gPath);
            Path elpPath = GenEllipsePath(this.ActualWidth, this.ActualHeight);
            this.gd.Children.Add(elpPath);
            Path circlePath=GenCirclePath(this.ActualWidth,this.ActualHeight);
            this.gd.Children.Add(circlePath);
        }

        private Path GenCirclePath(double actualWidth, double actualHeight)
        {
            EllipseGeometry circleGeo = new EllipseGeometry(new Point(actualWidth / 2, actualHeight / 2),
                actualHeight / 2-50, actualHeight / 2-50);
            Path circlePath = new Path();
            circlePath.Stroke = new SolidColorBrush(Colors.Blue);
            circlePath.StrokeThickness = 20;
            circlePath.Data = circleGeo;
            return circlePath;
        }

        private Path GenEllipsePath(double actualWidth, double actualHeight)
        {
            Path elpPath = new Path();
            elpPath.Stroke = new SolidColorBrush(Colors.Yellow);
            elpPath.StrokeThickness = 20;
            EllipseGeometry elpGeo= GenEllipseGeo(actualWidth, actualHeight);
            elpPath.Data= elpGeo;
            return elpPath;
        }

        private EllipseGeometry GenEllipseGeo(double actualWidth, double actualHeight)
        {
            EllipseGeometry elpGeo = new EllipseGeometry(new Point(actualWidth/2,actualHeight/2),
                actualWidth/2-50,actualHeight/2-50);
            return elpGeo;
        }

        private static Path GenLinePath(double actualWidth, double actualHeight)
        {
            PathGeometry pathGeo = GenLinePathGeometry(actualWidth,actualHeight);
            Path gPath = new Path();
            gPath.Fill = Brushes.Black;
            gPath.Stroke = Brushes.Red;
            gPath.StrokeThickness = 20;
            gPath.Data = pathGeo;
            return gPath;
        }

        private static Path GenRectanglePath(double actualWidth, double actualHeight)
        {
            RectangleGeometry rectGeo = GenRectGeometry(actualWidth, actualWidth);
            Path rectPath = new Path();
            rectPath.Fill = Brushes.Cyan;
            rectPath.Stroke = Brushes.Black;
            rectPath.StrokeThickness = 10;
            rectPath.Data = rectGeo;
            return rectPath;
        }

        private static RectangleGeometry GenRectGeometry(double actualWidth, double actualHeight)
        {
            RectangleGeometry myRectangleGeometry = new RectangleGeometry();
            myRectangleGeometry.Rect = new Rect(0, 0, actualWidth, actualHeight);
            return myRectangleGeometry;
        }

        private static PathGeometry GenLinePathGeometry(double actualWidth, double actualHeight)
        {
            PathGeometry pathGeo = new PathGeometry();
            PathFigure pf1 = new PathFigure();
            pf1.StartPoint = new Point(0, 0);
            pf1.Segments.Add(new LineSegment(new Point(actualWidth, actualHeight), true));
            pathGeo.Figures.Add(pf1);
            return pathGeo;
        }
    }
}

 

标签:actualHeight,using,System,actualWidth,new,Path,WPF,RectangleGeometry
From: https://www.cnblogs.com/Fred1987/p/18249610

相关文章

  • WPF RenderTargetBitmap DrawingVisual DrawingContext DrawImage DrawRectangle Draw
    usingSystem;usingSystem.Collections.Generic;usingSystem.Globalization;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingSystem.Windows;usingSystem.Windows.Controls;usingSystem.Windows.Data;usingSystem.Windows.Documents;......
  • WPF Image ZoomIn ZoomOut Pan/Move Rotate
    <Windowx:Class="WpfApp162.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:d="http://schemas.microsoft......
  • wpfui:一个开源免费具有现代化设计趋势的WPF控件库
    wpfui介绍wpfui是一款开源免费(MIT协议)具有现代化设计趋势的WPF界面库。wpfui为wpf的界面开发提供了流畅的体验,提供了一个简单的方法,让使用WPF编写的应用程序跟上现代设计趋势。截止写这篇文章,该项目获得了6.7kstarts。最近我也在使用wpfui,整体使用下来感觉非常不错,因此想写一......
  • DevExpress WPF中文教程:Grid - 如何完成列和编辑器配置(设计时)?
    DevExpressWPF拥有120+个控件和库,将帮助您交付满足甚至超出企业需求的高性能业务应用程序。通过DevExpressWPF能创建有着强大互动功能的XAML基础应用程序,这些应用程序专注于当代客户的需求和构建未来新一代支持触摸的解决方案。无论是Office办公软件的衍伸产品,还是以数据为中心......
  • WPF-DataGrid 样式设置
    在wpf中使用DataGrid虽然方便,但是其默认样式往往很难满足需求,而修改模板往往由比较麻烦,很多时候我们会用ListBox或ListView+DataTemplate来实现同样效果,但为了有些时候需要应用,这里记录一下一些基本属性设置方法,以免忘记。code<Windowx:Class="WpfApp7.MainWindow"......
  • xpath使用contains文本定位不到元素的原因及解决方法
    某些情况下,前端开发可能出现如下的代码<uni-viewdata-v-fc36b70f=""class="letter_city_item">"波特兰;"<spandata-v-fc36b70f=""class="gray">PDX</span></uni-view><uni-viewdata-v-fc36b70f=&quo......
  • WPF/C#:异常处理
    什么是异常?在C#中,异常是在程序执行过程中发生的特殊情况,例如尝试除以零、访问不存在的文件、网络连接中断等。这些情况会中断程序的正常流程。当C#程序中发生这种特殊情况时,会创建一个异常对象并将其抛出。这个异常对象包含了关于异常的详细信息,如异常类型和异常发生时的程序状......
  • WPF/C#:程序关闭的三种模式
    ShutdownMode枚举类型介绍ShutdownMode是一个枚举类型,它定义了WPF应用程序的关闭方式。这个枚举类型有三个成员:OnLastWindowClose:当最后一个窗口关闭或者调用System.Windows.Application.Shutdown方法时,应用程序会关闭。OnMainWindowClose:当主窗口关闭或者调用System.Windows.......
  • 在Linux中,如何将二进制文件添加到 $PATH 变量中?
    在Linux系统中,$PATH是一个环境变量,它定义了操作系统在执行命令时搜索可执行文件的目录。要将一个二进制文件添加到$PATH中,你可以按照以下步骤操作:找到二进制文件的路径:首先,你需要知道二进制文件的确切位置。使用which命令或者find命令来查找文件的位置。例如:whichyou......
  • WPF dependency property to customize control in usercontrol
    //usercontrol<UserControlx:Class="WpfApp157.ImageListBox"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xm......