基本信息
源码名称:C# 自定义控件:柱形液位动态展示UI
源码大小:0.08M
文件格式:.rar
开发语言:C#
更新时间:2017-02-11
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559

本次赞助数额为: 2 元 
   源码介绍
自定义控件 液位动态展示

public class SingnalLight : ContentControl
    {
        public int ValueA
        {
            get { return (int)GetValue(ValueAProperty); }
            set { SetValue(ValueAProperty, value); }
        }

        public double LightHeight
        {
            get { return (double)GetValue(LightHeightProperty); }
            set { SetValue(LightHeightProperty, value); }
        }

        public double X
        {
            get { return (double)GetValue(XProperty); }
            set { SetValue(XProperty, value); }
        }

        public double Y
        {
            get { return (double)GetValue(YProperty); }
            set { SetValue(YProperty, value); }
        }

        public SingnalLight()
        {
            this.AllowDrop = true;
        }

        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);
            if (e.LeftButton == MouseButtonState.Pressed)
            {
                _currentPoint = e.GetPosition(this);
                X = _currentPoint.X - _startPoint.X;
                Y = _currentPoint.Y - _startPoint.Y;
            }
        }

        protected override void OnMouseDown(MouseButtonEventArgs e)
        {
            base.OnMouseDown(e);
            _startPoint = e.GetPosition(this);
            this.CaptureMouse();
        }

        protected override void OnMouseUp(MouseButtonEventArgs e)
        {
            base.OnMouseUp(e);
            this.ReleaseMouseCapture();
        }

        protected override Size MeasureOverride(Size constraint)
        {
            if (ActualHeight > 0) LightHeight = ActualHeight * .7;
            return base.MeasureOverride(constraint);
        }

        protected override Size ArrangeOverride(Size arrangeBounds)
        {
            return base.ArrangeOverride(arrangeBounds);
        }

        static SingnalLight()
        {
            DefaultStyleKeyProperty.OverrideMetadata(typeof(SingnalLight), new FrameworkPropertyMetadata(typeof(SingnalLight)));
        }

        public static readonly DependencyProperty LightHeightProperty =
            DependencyProperty.Register("LightHeight", typeof(double), typeof(SingnalLight), new PropertyMetadata((double)0));

        public static readonly DependencyProperty ValueAProperty =
            DependencyProperty.Register("ValueA", typeof(int), typeof(SingnalLight), new PropertyMetadata(0));

        public static readonly DependencyProperty XProperty =
            DependencyProperty.Register("X", typeof(double), typeof(SingnalLight), new PropertyMetadata((double)0));

        public static readonly DependencyProperty YProperty =
            DependencyProperty.Register("Y", typeof(double), typeof(SingnalLight), new PropertyMetadata((double)0));

        private Point _startPoint;
        private Point _currentPoint;
    }