Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
The next code goes wrong after e.Graphics.RotateTransform(30);
C#
public Form1()
{
    InitializeComponent();

    this.BackColor = Color.Black;

    this.DoubleBuffered = true;
    this.Paint += Draw;
    this.Invalidate();
}

private void Draw(object sender, System.Windows.Forms.PaintEventArgs e)
{
    GraphicsPath path = new GraphicsPath();

    path.AddRectangle(new Rectangle(50, 50, 100, 20));

    using (PathGradientBrush pgb = new PathGradientBrush(path))
    {
        pgb.FocusScales = new PointF(1f, 0f);
        pgb.CenterColor = Color.FromArgb(255, 255, 255, 255);
        pgb.SurroundColors = new Color[] { Color.FromArgb(0, 255, 255, 255) };
        e.Graphics.RotateTransform(30); // Error!
        e.Graphics.FillRectangle(pgb, 0, 0, 200, 200);
    }
}



Right:
Without e.Graphics.RotateTransform(30);
https://social.msdn.microsoft.com/Forums/getfile/542870[^]

Wrong:
With e.Graphics.RotateTransform(30);
https://social.msdn.microsoft.com/Forums/getfile/542871[^]

How to fix?
I think i should also transform PathGradientBrush.
Posted
Updated 11-Oct-14 4:16am
v2
Comments
Dave Kreskowiak 10-Oct-14 8:14am    
Why is it every newb thinks that the error message isn't important?
Ziya1995 10-Oct-14 8:46am    
It is not a message, it is right, but the result doesn't suit, look at the second picture.
Dave Kreskowiak 10-Oct-14 18:28pm    
Sorry, but I don't click on links I don't trust.

Also, your question has the word "error" in a couple of places, so...

Lastly, what do you think should be correct? I can't see that so I don't know what you're expecting.
Ziya1995 11-Oct-14 2:49am    
The word "Error" shows what i call as error, not what compiler calls.

You can't click on the links, this is all the problem, but let me explain, just copy the code and check out and you will see that it results a messy image.
And then remove the RotateTransform line and check out again to see the right image. I wanna rotate that right image.

It is just simple to understand and even to solve.

1 solution

the thing is that you're filling an rectangle with that brush completely different from the path you made the brush try this
C#
private void Draw(object sender, System.Windows.Forms.PaintEventArgs e)
		{
			GraphicsPath path = new GraphicsPath();
			
			path.AddRectangle(new Rectangle(50, 50, 100, 20));

			using (PathGradientBrush pgb = new PathGradientBrush(path))
			{
				pgb.FocusScales = new PointF(1f, 0f);
				pgb.CenterColor = Color.FromArgb(255, 255, 255, 255);
				pgb.SurroundColors = new Color[] { Color.FromArgb(0, 255, 255, 255) };
				e.Graphics.RotateTransform(30); // error!
				e.Graphics.FillPath(pgb, path);
				//e.Graphics.FillRectangle(pgb, 0, 0, 200, 200);
				
			}
		}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900