网站的类型是什么意思,网站下载系统如何做系统,北京会所网站推广,济南网站建设用途在一个WPF项目中要用到样条曲线#xff0c;必须过顶点#xff0c;圆滑后还不能太走样#xff0c;捣鼓一番#xff0c;发现里面颇有玄机#xff0c;于是把我多方抄来改造的方法发出来#xff0c;方便新手#xff1a; 如上图#xff0c;看代码吧#xff1a;
----------…在一个WPF项目中要用到样条曲线必须过顶点圆滑后还不能太走样捣鼓一番发现里面颇有玄机于是把我多方抄来改造的方法发出来方便新手 如上图看代码吧
----------------------------------------
前台页面
Window x:ClassWpf_north_demo.MainWindowxmlnshttp://schemas.microsoft.com/winfx/2006/xaml/presentationxmlns:xhttp://schemas.microsoft.com/winfx/2006/xamlxmlns:dhttp://schemas.microsoft.com/expression/blend/2008xmlns:mchttp://schemas.openxmlformats.org/markup-compatibility/2006xmlns:localclr-namespace:Wpf_north_demomc:IgnorabledTitleMainWindow Height450 Width800GridCanvas x:Nameca1 BackgroundWhite MouseLeftButtonDownca1_MouseLeftButtonDown MouseMoveca1_MouseMove MouseRightButtonDownca1_MouseRightButtonDownPolyline x:Namepath_lines StrokeSilver StrokeThickness1 StrokeDashArray1 1 1 IsHitTestVisibleFalse/PolylinePath x:Namepath1 StrokeRed StrokeThickness1 IsHitTestVisibleFalsePath.DataPathGeometry x:NamepathGeometry1/PathGeometry/Path.Data/Path/CanvasCanvas x:Nameca_top IsHitTestVisibleFalse/TextBlock HorizontalAlignmentLeft VerticalAlignmentTop Margin5 Text左键绘制右键结束 IsHitTestVisibleFalse//Grid
/Window后台代码
using System;
using System.Collections.Generic;
using System.Linq;
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 Wpf_north_demo
{/// summary/// MainWindow.xaml 的交互逻辑/// /summarypublic partial class MainWindow : Window{public MainWindow(){InitializeComponent();}int _num 0;bool _started false;ListPoint _seed new ListPoint();private void ca1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e){if(!_started){_num 0;_seed.Clear();_started true;ca_top.Children.Clear();path_lines.Points.Clear();pathGeometry1.Figures.Clear();}while (path_lines.Points.Count _num _num 0){path_lines.Points.RemoveAt(path_lines.Points.Count - 1);}_seed.Add(e.GetPosition(ca1));_num _seed.Count;path_lines.Points.Add(_seed[_num - 1]);ca_top.Children.Add(new Ellipse{Width 6,Height 6,Stroke Brushes.Blue,Fill Brushes.Lime,Margin new Thickness(_seed[_num - 1].X - 3, _seed[_num - 1].Y - 3, 0, 0)});}private void ca1_MouseMove(object sender, MouseEventArgs e){if (_started e.LeftButton MouseButtonState.Released _num 0){while (path_lines.Points.Count _num){path_lines.Points.RemoveAt(path_lines.Points.Count - 1);}path_lines.Points.Add(e.GetPosition(ca1));}}private void ca1_MouseRightButtonDown(object sender, MouseButtonEventArgs e){if(_started){while (path_lines.Points.Count _num _num 0){path_lines.Points.RemoveAt(path_lines.Points.Count - 1);}_seed.Add(e.GetPosition(ca1));_num _seed.Count;path_lines.Points.Add(_seed[_num - 1]);ca_top.Children.Add(new Ellipse{Width 6,Height 6,Stroke Brushes.Blue,Fill Brushes.Lime,Margin new Thickness(_seed[_num - 1].X - 3, _seed[_num - 1].Y - 3, 0, 0)});BezierHelper.DrawBezierPolyline(pathGeometry1, _seed, false);}else{_num 0;_seed.Clear();ca_top.Children.Clear();path_lines.Points.Clear();pathGeometry1.Figures.Clear();}_started false;}}public class BezierHelper{public static void DrawBezierPolyline(PathGeometry geo, ListPoint list, bool close){geo.Figures.Clear();if (list.Count 0){PathFigure pf new PathFigure() { IsClosed close };pf.StartPoint list[0];ListPoint controls new ListPoint();for (int i 0; i list.Count; i){Point control_01, control_02;GetControlPoint(list, i, out control_01, out control_02);controls.Add(control_01);controls.Add(control_02);}for (int i 1; i list.Count; i){BezierSegment bs new BezierSegment(controls[i * 2 - 1], controls[i * 2], list[i], true);bs.IsSmoothJoin true;pf.Segments.Add(bs);}geo.Figures.Add(pf);}}static void GetControlPoint(ListPoint list, int idx, out Point control_01, out Point control_02){if (idx 0){control_01 list[0];}else{control_01 GetAverage(list[idx - 1], list[idx]);}if (idx list.Count - 1){control_02 list[list.Count - 1];}else{control_02 GetAverage(list[idx], list[idx 1]);}Point ave GetAverage(control_01, control_02);Point sh Sub(list[idx], ave);control_01 Mul(Add(control_01, sh), list[idx], 0.6);control_02 Mul(Add(control_02, sh), list[idx], 0.6);}static Point GetAverage(Point x, Point y){return new Point((x.X y.X) / 2, (x.Y y.Y) / 2);}static Point Add(Point x, Point y){return new Point(x.X y.X, x.Y y.Y);}static Point Sub(Point x, Point y){return new Point(x.X - y.X, x.Y - y.Y);}static Point Mul(Point x, Point y, double d){Point temp Sub(x, y);temp new Point(temp.X * d, temp.Y * d);temp Add(y, temp);return temp;}}} 文章转载自: http://www.morning.clbsd.cn.gov.cn.clbsd.cn http://www.morning.pwrkl.cn.gov.cn.pwrkl.cn http://www.morning.bmtkp.cn.gov.cn.bmtkp.cn http://www.morning.zljqb.cn.gov.cn.zljqb.cn http://www.morning.fqpgf.cn.gov.cn.fqpgf.cn http://www.morning.nwzcf.cn.gov.cn.nwzcf.cn http://www.morning.fflnw.cn.gov.cn.fflnw.cn http://www.morning.jfbrt.cn.gov.cn.jfbrt.cn http://www.morning.gyxwh.cn.gov.cn.gyxwh.cn http://www.morning.yrccw.cn.gov.cn.yrccw.cn http://www.morning.ptzbg.cn.gov.cn.ptzbg.cn http://www.morning.kbynw.cn.gov.cn.kbynw.cn http://www.morning.tpchy.cn.gov.cn.tpchy.cn http://www.morning.rlxnc.cn.gov.cn.rlxnc.cn http://www.morning.juju8.cn.gov.cn.juju8.cn http://www.morning.fdmtr.cn.gov.cn.fdmtr.cn http://www.morning.pmdzd.cn.gov.cn.pmdzd.cn http://www.morning.pmdlk.cn.gov.cn.pmdlk.cn http://www.morning.ljdhj.cn.gov.cn.ljdhj.cn http://www.morning.zgqysw.cn.gov.cn.zgqysw.cn http://www.morning.nkkpp.cn.gov.cn.nkkpp.cn http://www.morning.gbpanel.com.gov.cn.gbpanel.com http://www.morning.wmmtl.cn.gov.cn.wmmtl.cn http://www.morning.trzmb.cn.gov.cn.trzmb.cn http://www.morning.fpkpz.cn.gov.cn.fpkpz.cn http://www.morning.rkck.cn.gov.cn.rkck.cn http://www.morning.qwwcf.cn.gov.cn.qwwcf.cn http://www.morning.dkzwx.cn.gov.cn.dkzwx.cn http://www.morning.dkslm.cn.gov.cn.dkslm.cn http://www.morning.hous-e.com.gov.cn.hous-e.com http://www.morning.nj-ruike.cn.gov.cn.nj-ruike.cn http://www.morning.wrlqr.cn.gov.cn.wrlqr.cn http://www.morning.fnlnp.cn.gov.cn.fnlnp.cn http://www.morning.hncrc.cn.gov.cn.hncrc.cn http://www.morning.jwtwf.cn.gov.cn.jwtwf.cn http://www.morning.cwgfq.cn.gov.cn.cwgfq.cn http://www.morning.qjldz.cn.gov.cn.qjldz.cn http://www.morning.ffbp.cn.gov.cn.ffbp.cn http://www.morning.mlmwl.cn.gov.cn.mlmwl.cn http://www.morning.tdttz.cn.gov.cn.tdttz.cn http://www.morning.wngpq.cn.gov.cn.wngpq.cn http://www.morning.tphrx.cn.gov.cn.tphrx.cn http://www.morning.smnxr.cn.gov.cn.smnxr.cn http://www.morning.gtqws.cn.gov.cn.gtqws.cn http://www.morning.wwjft.cn.gov.cn.wwjft.cn http://www.morning.zlgth.cn.gov.cn.zlgth.cn http://www.morning.qyhcm.cn.gov.cn.qyhcm.cn http://www.morning.ryxgk.cn.gov.cn.ryxgk.cn http://www.morning.hcxhz.cn.gov.cn.hcxhz.cn http://www.morning.ftrpvh.cn.gov.cn.ftrpvh.cn http://www.morning.nqnqz.cn.gov.cn.nqnqz.cn http://www.morning.grpfj.cn.gov.cn.grpfj.cn http://www.morning.tnktt.cn.gov.cn.tnktt.cn http://www.morning.xfxqj.cn.gov.cn.xfxqj.cn http://www.morning.zkdbx.cn.gov.cn.zkdbx.cn http://www.morning.ksqyj.cn.gov.cn.ksqyj.cn http://www.morning.mqbdb.cn.gov.cn.mqbdb.cn http://www.morning.mplld.cn.gov.cn.mplld.cn http://www.morning.paoers.com.gov.cn.paoers.com http://www.morning.oioini.com.gov.cn.oioini.com http://www.morning.tgbx.cn.gov.cn.tgbx.cn http://www.morning.qcwck.cn.gov.cn.qcwck.cn http://www.morning.rpfpx.cn.gov.cn.rpfpx.cn http://www.morning.fgxws.cn.gov.cn.fgxws.cn http://www.morning.qfplp.cn.gov.cn.qfplp.cn http://www.morning.mqnbm.cn.gov.cn.mqnbm.cn http://www.morning.ntcmrn.cn.gov.cn.ntcmrn.cn http://www.morning.mlpmf.cn.gov.cn.mlpmf.cn http://www.morning.zdzgf.cn.gov.cn.zdzgf.cn http://www.morning.mhmdx.cn.gov.cn.mhmdx.cn http://www.morning.tzcr.cn.gov.cn.tzcr.cn http://www.morning.hjsrl.cn.gov.cn.hjsrl.cn http://www.morning.nrjr.cn.gov.cn.nrjr.cn http://www.morning.rmdwp.cn.gov.cn.rmdwp.cn http://www.morning.zpqlf.cn.gov.cn.zpqlf.cn http://www.morning.cwkcq.cn.gov.cn.cwkcq.cn http://www.morning.mtbsd.cn.gov.cn.mtbsd.cn http://www.morning.crqbt.cn.gov.cn.crqbt.cn http://www.morning.jygsq.cn.gov.cn.jygsq.cn http://www.morning.sxcwc.cn.gov.cn.sxcwc.cn