Explore Enterprise Education Gitee Premium Gitee AI AI teammates
Fetch the repository succeeded.
Donate
Please sign in before you donate.
Scan WeChat QR to Pay
Cancel
Complete
Prompt
Switch to Alipay.
OK
Cancel
1 Star 0 Fork 4

yusin/Desktop自定义控件库

Create your Gitee Account
Explore and code with more than 14 million developers,Free private repositories !:)
Sign up
Already have an account? Sign in
文件
master
Branches (1)
master
master
Branches (1)
master
Clone or Download
Clone/Download
Prompt
To download the code, please copy the following command and execute it in the terminal
To ensure that your submitted code identity is correctly recognized by Gitee, please execute the following command.
When using the SSH protocol for the first time to clone or push code, follow the prompts below to complete the SSH configuration.
1 Generate RSA keys.
2 Obtain the content of the RSA public key and configure it in SSH Public Keys
To use SVN on Gitee, please visit the usage guide
When using the HTTPS protocol, the command line will prompt for account and password verification as follows. For security reasons, Gitee recommends configure and use personal access tokens instead of login passwords for cloning, pushing, and other operations.
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # Private Token
master
Branches (1)
master
DesktopCustomControl
/
CustomComponent
/
CoordinateSystem.cs
DesktopCustomControl
/
CustomComponent
/
CoordinateSystem.cs
CoordinateSystem.cs 8.52 KB
Copy Edit Raw Blame History
写代码的厨子 authored 2020年05月07日 04:34 +08:00 . 同步
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229
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 CustomControl.CustomComponent
{
/// <summary>
/// 坐标系
/// </summary>
public class CoordinateSystem : Shape
{
private StreamGeometry streamGeometry;
private static double XStaticValue = 0.0; //X轴空留距离基准
private static double YStaticValue = 0.0; //Y轴空留距离基准
/// <summary>
/// X轴刻度坐标集合
/// </summary>
public Point[] XTicks { get; set; }
/// <summary>
/// Y轴刻度坐标集合
/// </summary>
public Point[] YTicks { get; set; }
static CoordinateSystem()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(CoordinateSystem), new FrameworkPropertyMetadata(typeof(CoordinateSystem)));
}
protected override Geometry DefiningGeometry
{
get
{
using (StreamGeometryContext context = streamGeometry.Open())
{
DrawCoordinateSystem(context, this);
}
return streamGeometry;
}
}
/// <summary>
/// 绘制坐标系
/// </summary>
/// <param name="context"></param>
/// <param name="coordinate"></param>
private void DrawCoordinateSystem(StreamGeometryContext context, CoordinateSystem coordinate)
{
//画X轴
context.BeginFigure(coordinate.CenterPoint, true, false);
context.LineTo(coordinate.XEndPoint, true, true);
Point[] xPoints = new Point[3] { new Point(coordinate.XEndPoint.X - 10, coordinate.XEndPoint.Y - 10), new Point(coordinate.XEndPoint.X + 2, coordinate.XEndPoint.Y), new Point(coordinate.XEndPoint.X - 10, coordinate.XEndPoint.Y + 10) };
context.BeginFigure(xPoints[0], true, false);
context.PolyLineTo(xPoints, true, true);
//画Y轴
context.BeginFigure(coordinate.CenterPoint, true, false);
context.LineTo(coordinate.YEndPoint, true, true);
Point[] yPoints = new Point[3] { new Point(coordinate.YEndPoint.X - 10, coordinate.YEndPoint.Y + 10), new Point(coordinate.YEndPoint.X, coordinate.YEndPoint.Y), new Point(coordinate.YEndPoint.X + 10, coordinate.YEndPoint.Y + 10) };
context.BeginFigure(yPoints[0], true, false);
context.PolyLineTo(yPoints, true, true);
/***----画刻度----***/
//X方向
double XLength = coordinate.XEndPoint.X - coordinate.CenterPoint.X;
XStaticValue = XLength / coordinate.XCoordinateTicks;
double XTickInterval = (XLength - XStaticValue / 3) / coordinate.XCoordinateTicks;
coordinate.XTickValue = XTickInterval;
XTicks = new Point[coordinate.XCoordinateTicks];
for (int i = 0; i < XTicks.Length; i++)
{
XTicks[i] = new Point(coordinate.CenterPoint.X + (i + 1) * XTickInterval, coordinate.XEndPoint.Y);
}
DrawTicks(context, XTicks, 9.0, coordinate, "X");
//Y方向
double YLength = coordinate.CenterPoint.Y - coordinate.YEndPoint.Y;
YStaticValue = YLength / coordinate.YCoordinateTicks;
double YTickInterval = (YLength - YStaticValue / 3) / coordinate.YCoordinateTicks;
coordinate.YTickValue = YTickInterval;
YTicks = new Point[coordinate.YCoordinateTicks];
for (int i = 0; i < YTicks.Length; i++)
{
YTicks[i] = new Point(coordinate.CenterPoint.X, coordinate.CenterPoint.Y - (i + 1) * YTickInterval);
}
DrawTicks(context, YTicks, 9.0, coordinate, "Y");
context.Close();
}
//画刻度
private void DrawTicks(StreamGeometryContext context,Point[] beginPoint, double tickHeight, CoordinateSystem coordinate, string axis)
{
int index = 0;
while(index < beginPoint.Length)
{
context.BeginFigure(beginPoint[index], true, false);
if (axis == "X")
context.LineTo(new Point(beginPoint[index].X, coordinate.CenterPoint.Y - tickHeight), true, true);
else if (axis == "Y")
context.LineTo(new Point(coordinate.CenterPoint.X + tickHeight, beginPoint[index].Y), true, true);
else { }
index++;
}
}
public CoordinateSystem()
{
streamGeometry = new StreamGeometry();
}
/// <summary>
/// 坐标原点
/// </summary>
public Point CenterPoint
{
get { return (Point)GetValue(CenterPointProperty); }
set { SetValue(CenterPointProperty, value); }
}
public static readonly DependencyProperty CenterPointProperty =
DependencyProperty.Register("CenterPoint", typeof(Point), typeof(CoordinateSystem), new PropertyMetadata(default(Point), OnCoordinateSystemChanged));
/// <summary>
/// X轴长度
/// </summary>
public Point XEndPoint
{
get { return (Point)GetValue(XEndPointProperty); }
set { SetValue(XEndPointProperty, value); }
}
public static readonly DependencyProperty XEndPointProperty =
DependencyProperty.Register("XEndPoint", typeof(Point), typeof(CoordinateSystem), new PropertyMetadata(default(Point), OnCoordinateSystemChanged));
/// <summary>
/// Y轴长度
/// </summary>
public Point YEndPoint
{
get { return (Point)GetValue(YEndPointProperty); }
set { SetValue(YEndPointProperty, value); }
}
public static readonly DependencyProperty YEndPointProperty =
DependencyProperty.Register("YEndPoint", typeof(Point), typeof(CoordinateSystem), new PropertyMetadata(default(Point), OnCoordinateSystemChanged));
/// <summary>
/// X刻度数
/// </summary>
public int XCoordinateTicks
{
get { return (int)GetValue(XCoordinateTicksProperty); }
set { SetValue(XCoordinateTicksProperty, value); }
}
public static readonly DependencyProperty XCoordinateTicksProperty =
DependencyProperty.Register("XCoordinateTicks", typeof(int), typeof(CoordinateSystem), new PropertyMetadata(5, OnCoordinateSystemChanged));
/// <summary>
/// Y刻度数
/// </summary>
public int YCoordinateTicks
{
get { return (int)GetValue(YCoordinateTicksProperty); }
set { SetValue(YCoordinateTicksProperty, value); }
}
public static readonly DependencyProperty YCoordinateTicksProperty =
DependencyProperty.Register("YCoordinateTicks", typeof(int), typeof(CoordinateSystem), new PropertyMetadata(5, OnCoordinateSystemChanged));
/// <summary>
/// X轴平均刻度值
/// </summary>
public double XTickValue
{
get { return (double)GetValue(XTickValueProperty); }
set { SetValue(XTickValueProperty, value); }
}
public static readonly DependencyProperty XTickValueProperty =
DependencyProperty.Register("XTickValue", typeof(double), typeof(CoordinateSystem), new PropertyMetadata(default(double)));
/// <summary>
/// Y轴平均刻度值
/// </summary>
public double YTickValue
{
get { return (double)GetValue(YTickValueProperty); }
set { SetValue(YTickValueProperty, value); }
}
public static readonly DependencyProperty YTickValueProperty =
DependencyProperty.Register("YTickValue", typeof(double), typeof(CoordinateSystem), new PropertyMetadata(default(double)));
//更新坐标系
private static void OnCoordinateSystemChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if(d != null && d is CoordinateSystem)
{
var coordinate = d as CoordinateSystem;
coordinate.DrawCoordinateSystem(coordinate.streamGeometry.Open(), coordinate);
}
}
}
}
Loading...
Report
Report success
We will send you the feedback within 2 working days through the letter!
Please fill in the reason for the report carefully. Provide as detailed a description as possible.
Please select a report type
Cancel
Send
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

About

Wpf/Winform自定义控件库
No labels
Apache-2.0
Use Apache-2.0
Cancel

Releases

No release

Contributors

All

Activities

can not load any more
Edit
About
Homepage
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C#
1
https://gitee.com/yusin/DesktopCustomControl.git
git@gitee.com:yusin/DesktopCustomControl.git
yusin
DesktopCustomControl
Desktop自定义控件库
master
Going to Help Center

Search

Comment
Repository Report
Back to the top
Login prompt
This operation requires login to the code cloud account. Please log in before operating.
Go to login
No account. Register

AltStyle によって変換されたページ (->オリジナル) /