开发者

WPF radial-gradients

开发者 https://www.devze.com 2023-01-11 23:15 出处:网络
I have tried the following code, but the last line causes an error *Error Argument \'1\': cannot convert from \'System.Windows.Media.RadialGradientBrush\' to \'System.Drawing.Brush\'

I have tried the following code, but the last line causes an error *Error Argument '1': cannot convert from 'System.Windows.Media.RadialGradientBrush' to 'System.Drawing.Brush' *

I have visual studio 2008

<CODE>

/*
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows;
*/
        private void Main_Screen_Paint(object sender, PaintEventArgs e)
        {
            Rectangle rBoundingBox = e.ClipRectangle;
            RadialGradientBrush radialGradient = new RadialGradientBrush();
            radialGradient.Gradien开发者_Python百科tOrigin = new System.Windows.Point(5, 5);
            radialGradient.Center = new System.Windows.Point(5, 5);
            radialGradient.RadiusX = 5;
            radialGradient.RadiusY = 5;
            radialGradient.GradientStops.Add(new GradientStop(Colors.Yellow, 0.0));
            radialGradient.GradientStops.Add(new GradientStop(Colors.Red, 0.25));
            radialGradient.GradientStops.Add(new GradientStop(Colors.Blue, 0.75));
            radialGradient.GradientStops.Add(new GradientStop(Colors.LimeGreen, 1.0));
            radialGradient.Freeze();

        rBoundingBox.Inflate(-5, -5);

        e.Graphics.FillEllipse(radialGradient, rBoundingBox);
    }

can anyone tell me how to fill an elipse with the radial brush?


From void Main_Screen_Paint(object sender, PaintEventArgs e) it is clear that your application is Windows.Forms. The RadialGradientBrush however is a WPF component. That's just not compatible.

Personally I think it borders on silly that the WPF namespaces start with System.Windows, but such is life.

0

精彩评论

暂无评论...
验证码 换一张
取 消