예제 #1
0
    public void FillGradientBeam(Graphics g, Color Col1, Color Col2, Rectangle rect, GradientAlignment align)
    {
        SmoothingMode stored = g.SmoothingMode;
        ColorBlend    Blend  = new ColorBlend();

        g.SmoothingMode = SmoothingMode.HighQuality;
        LinearGradientBrush PathGradient;

        switch (align)
        {
        case GradientAlignment.Vertical:
            PathGradient    = new LinearGradientBrush(new Point(rect.X, rect.Y), new Point(rect.X + rect.Width - 1, rect.Y), Color.Black, Color.Black);
            Blend.Positions = new[] { 0, 1 / 2f, 1 };

            Blend.Colors = new[] { Col1, Col2, Col1 };
            PathGradient.InterpolationColors = Blend;
            g.FillRectangle(PathGradient, rect);
            break;

        case GradientAlignment.Horizontal:
            PathGradient    = new LinearGradientBrush(new Point(rect.X, rect.Y), new Point(rect.X, rect.Y + rect.Height), Color.Black, Color.Black);
            Blend.Positions = new[] { 0, 1 / 2f, 1 };
            Blend.Colors    = new[] {
                Col1,
                Col2,
                Col1
            };
            PathGradient.InterpolationColors = Blend;
            PathGradient.RotateTransform(0);
            g.FillRectangle(PathGradient, rect);
            break;
        }
        g.SmoothingMode = stored;
    }
예제 #2
0
    public void FillGradientBeam(Graphics g, Color Col1, Color Col2, Rectangle rect, GradientAlignment align)
    {
        SmoothingMode stored = g.SmoothingMode;
        ColorBlend Blend = new ColorBlend();
        g.SmoothingMode = SmoothingMode.HighQuality;
        LinearGradientBrush PathGradient;
        switch (align)
        {
            case GradientAlignment.Vertical:
                PathGradient = new LinearGradientBrush(new Point(rect.X, rect.Y), new Point(rect.X + rect.Width - 1, rect.Y), Color.Black, Color.Black);
                Blend.Positions = new[] { 0, 1 / 2f, 1 };

                Blend.Colors = new[]{Col1,Col2,Col1};
                PathGradient.InterpolationColors = Blend;
                g.FillRectangle(PathGradient, rect);
                break;
            case GradientAlignment.Horizontal:
                PathGradient = new LinearGradientBrush(new Point(rect.X, rect.Y), new Point(rect.X, rect.Y + rect.Height), Color.Black, Color.Black);
                Blend.Positions = new[]{0,1 / 2f,1 };
                Blend.Colors = new[]{
                    Col1,
                    Col2,
                    Col1
                };
                PathGradient.InterpolationColors = Blend;
                PathGradient.RotateTransform(0);
                g.FillRectangle(PathGradient, rect);
                break;
        }
        g.SmoothingMode = stored;
    }