コード例 #1
0
        protected virtual void OnAngleChanged(double Value)
        {
            if (!AngleChangeHandled)
            {
                var Angle = Value;

                var x = Angle * (1d / 180d) * Math.PI;
                var y = new Point(Math.Cos(x), Math.Sin(x));

                switch (GradientType)
                {
                case GradientType.Linear:
                    var Linear = Gradient.As <LinearGradientBrush>();
                    switch (GradientPosition)
                    {
                    case GradientPosition.End:
                        Linear.EndPoint = y;
                        break;

                    case GradientPosition.Start:
                        Linear.StartPoint = y;
                        break;
                    }
                    break;

                case GradientType.Radial:
                    var Radial = Gradient.As <RadialGradientBrush>();
                    switch (GradientPosition)
                    {
                    case GradientPosition.End:
                        Radial.Center = y;
                        break;

                    case GradientPosition.Start:
                        Radial.GradientOrigin = y;
                        break;
                    }
                    break;
                }
            }

            OnGradientChanged(new EventArgs <Brush>(Gradient));
        }
コード例 #2
0
        protected virtual void OnGradientPositionChanged(GradientPosition Value)
        {
            var Point = default(Point);

            switch (GradientType)
            {
            case GradientType.Linear:
                switch (Value)
                {
                case GradientPosition.End:
                    Point = Gradient.As <LinearGradientBrush>().EndPoint;
                    break;

                case GradientPosition.Start:
                    Point = Gradient.As <LinearGradientBrush>().StartPoint;
                    break;
                }
                break;

            case GradientType.Radial:
                switch (Value)
                {
                case GradientPosition.End:
                    Point = Gradient.As <RadialGradientBrush>().Center;
                    break;

                case GradientPosition.Start:
                    Point = Gradient.As <RadialGradientBrush>().GradientOrigin;
                    break;
                }
                break;
            }

            AngleChangeHandled = true;
            var x = Math.Acos(Point.X);

            Angle = x / Math.PI / (1d / 180d);
            AngleChangeHandled = false;

            OnGradientChanged(new EventArgs <Brush>(Gradient));
        }