简易的温度计控件实现
来源:互联网 发布:复权价格 知乎 编辑:程序博客网 时间:2024/04/30 15:52
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 Weather_Glasses_Control{ /// <summary> /// UserControl1.xaml 的交互逻辑 /// </summary> public partial class Weather_Glasses : UserControl { private double _maxT; //最大温度 private double _minT; //最小温度 private double _currentT; //当前温度 private RectangleGeometry rt; //显示的区域 private PathGeometry maskGeometry; public Weather_Glasses() : this(60.0, -40.0, 0.0) { } public Weather_Glasses(double maxT, double minT, double currentT) { InitializeComponent(); _maxT = maxT; _minT = minT; _currentT = currentT; maskGeometry = new PathGeometry(); rt = new RectangleGeometry(); rt.Rect = GetRectangle(); maskGeometry = Geometry.Combine(maskGeometry, rt, GeometryCombineMode.Union, null); mask.Clip = maskGeometry; } private Rect GetRectangle() { return new Rect(0, 300 - 89 + 30 - (_currentT + 40) / (_maxT - _minT) * (300 - 97 - 30 + 5) + 30, 100, (_currentT + 40) / (_maxT - _minT) * (300 - 97 - 30 + 5)); } public double CurrentT { get { return _currentT; } set { double new_currentT = value / 100.0 * (_maxT - _minT) + _minT; if (_currentT == new_currentT) { return; } else if (_currentT > new_currentT) //下降 { rt.Rect = GetRectangle(); maskGeometry = Geometry.Combine(maskGeometry, rt, GeometryCombineMode.Intersect, null); mask.Clip = maskGeometry; } else if (_currentT < new_currentT) //上升 { rt.Rect = GetRectangle(); maskGeometry = Geometry.Combine(maskGeometry, rt, GeometryCombineMode.Union, null); mask.Clip = maskGeometry; } _currentT = new_currentT; } } public double MinT { get { return _minT; } set { _minT = value; } } public double MaxT { get { return _maxT; } set { _maxT = value; } } }}
<UserControl x:Name="Glasses" x:Class="Weather_Glasses_Control.Weather_Glasses" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" mc:Ignorable="d" d:Height="300" Width="100"> <Viewbox StretchDirection="Both"> <Canvas Width="100" Height="300"> <Ellipse Fill="Gray" Width="100" Height="100" Canvas.Left="0" Canvas.Bottom="0"/> <Rectangle Fill="Gray" Width="40" Height="150" Canvas.Left="30" Canvas.Top="97"/> <Border Background="Gray" CornerRadius="200,200,0,0" Width="40" Height="20" Canvas.Left="30" Canvas.Top="78"/> <Ellipse Fill="White" Width="70" Height="70" Canvas.Left="15" Canvas.Bottom="15"/> <Rectangle Fill="White" Width="20" Height="150" Canvas.Left="40" Canvas.Top="97"/> <Border Background="White" CornerRadius="200,200,0,0" Width="20" Height="10" Canvas.Left="40" Canvas.Top="88"/> <Canvas Name="mask" Width="100" Height="300"> <Ellipse Fill="Green" Width="40" Height="40" Canvas.Left="30" Canvas.Bottom="30"/> <Rectangle Fill="Green" Width="10" Height="150" Canvas.Left="45" Canvas.Top="97"/> <Border Background="Green" CornerRadius="200,200,0,0" Width="10" Height="5" Canvas.Left="45" Canvas.Top="93"/> </Canvas> </Canvas> </Viewbox></UserControl>
阅读全文
0 0
- 简易的温度计控件实现
- ios 温度计的实现
- Thermometer—温度计控件
- java窗体简易控件的实现
- 使用LPC1768实现的数字时钟和温度计
- 温度计式样的时间
- 带温度计的杯子
- ad590温度计的毕业论文
- android左右侧滑菜单控件的简易实现
- 列表删除功能中条目控件的简易实现
- 类似于温度计的自定义SeekBar
- 我的Android进阶之旅------>Android利用温度传感器实现带动画效果的电子温度计
- Repeater控件的简易绑定
- 日期控件-1.javascript实现简易日历
- 简易计算器的实现
- 简易栈的实现
- 简易的文本实现
- 简易电子词典的实现
- 5-8 哈利·波特的考试(Floyd)
- sleep和wait
- 'TenantId(java.lang.String)' has private access in 'com.dxc.mongodb.TenantId'
- python中的re模块(正则表达式)
- Springmvc的注解
- 简易的温度计控件实现
- 三(2)、JSP九大内置对象——request(重要)
- 爬虫——多线程糗事百科案例
- NDK_APPLICATION_MK分析
- HDU5988(最小费用流)
- 太空飞行计划
- 东岱FabCost成本管理控制系统批量导入零件加工清单,助企业控制成本,提高加工效率
- Python类和继承
- Spring Boot application.propertis