看代码
private void Form1_Paint( object sender, PaintEventArgs e )
        {
            Graphics g = e.Graphics;
            LinearGradientBrush myBrush = new LinearGradientBrush( this.ClientRectangle, Color.Red, Color.Blue, LinearGradientMode.Vertical );
            g.FillRectangle( myBrush, this.ClientRectangle );
        }没有显示渐变效果,为什么?

解决方案 »

  1.   


      <Canvas Name="canvas"  Height="302" Width="285">
            <Canvas.Background>
                <LinearGradientBrush StartPoint="0,0.5" EndPoint="1,0.5">
                    <GradientStop Color="Red" Offset="0.0"></GradientStop>
                    <GradientStop Color="Yellow" Offset="0.25"></GradientStop>
                    <GradientStop Color="Green" Offset="0.5"></GradientStop>
                    <GradientStop Color="Blue" Offset="0.75"></GradientStop>
                </LinearGradientBrush>
            </Canvas.Background>
            <!--</Canvas>-->
        </Canvas>我刚在wpf里面试了下,可以实现不知道你那里面行不行
      

  2.   

    看了下 LinearGradientBrush对象 报了个异常 “myBrush.InterpolationColors”引发了“System.ArgumentException”类型的异常不知道是不是这个原因
      

  3.   

    我这边运行正常,建议楼主修复.netframwork
      

  4.   

    LS几个明眼人啊,我突然想起来这个项目用的是framework2.0.项目的框架是不能变了,话说framework2.0能渐变吗
      

  5.   

    framework2.0能渐变吗 能的话如何办 求解啊
      

  6.   

    using System.Drawing.Drawing2D;   
    这个引用添加了吗   
      

  7.   

    问题解决了,必须得在需要变色的控件所对应的paint事件中进行变色处理,否则无效!!哎  还是自己动手,丰衣足食啊