Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

.NET 

[Tutorial] Radial Gradients in GDI

A lot of the times I have come across people not knowing how to do radial gradients, so this is the explanation.

In GDI, it isn't called radial gradient, it is a PATH GRADIENT <- REMEMBER THAT NAME!

1. Define a path with a circle
Now, first of all we need to declare us a new graphics path, like this:

Code
Dim path As New GraphicsPath()

and second, add a new ellipse to it (this is our RADIAL part)
Code
path.AddEllipse(0, 0, 140, 70)

2. Make a brush! (To fill our gradient)
First, we use the path to make our brush.
Code
Dim pthGrBrush As New PathGradientBrush(path)

3. Set your colors!
Now, we set the center color of the gradient
Code
pthGrBrush.CenterColor = Color.White

Now, we set the outside color (this can be as many colors as you want, however the gradient we want only consists of an inside and outside color, so we only make one)
Code
Dim colors As Color() = {Color.Red}
pthGrBrush.SurroundColors = colors

4. Draw the radial gradient!
Now, we use our graphics to fill the ellipse (radial gradient)
Code
e.Graphics.FillEllipse(pthGrBrush, 0, 0, 140, 70)

This will produce something like this:
[img]http://www.blackhax.com/iqa/xBxGpdbtTstRCcNtvbIi.png[/img]

Now, to make it fade out just set your inside color to something, and out outside color to Color.Transparent

Complete Code:
Code
I will not post this complete code because if you want to learn, reading through this will teach you how, if you just copy we will know you are just a noob, and will never be able to code, no hard feelings.

This is a leading example of why you should use MSDN, I found this in little under 5 minutes ( http://msdn.microsoft.com/en-us/library/...brush.aspx )
[Image: 86251a37e635a21aea7eb7e014b0d820.gif]
Good job Tedd, so proud of you! <3.
Nice job tedd, looks pretty cool 🙂
(Oct 11, 2011 07:53 PM)Sapientia Wrote:  Nice job tedd, looks pretty cool 🙂
Hey thanks man :)

(Oct 11, 2011 07:44 PM)Facebook Inc Wrote:  Good job Tedd, so proud of you! <3.

Thanks really appreciate the comment :)
[Image: 86251a37e635a21aea7eb7e014b0d820.gif]
I actually added radial gradient into 1.5.3 of the theme base! DrawRadial. :)
(Oct 11, 2011 08:07 PM)6e756c6c Wrote:  I actually added radial gradient into 1.5.3 of the theme base! DrawRadial. :)

Awesome, been waiting on that haha kept having to write it myself :)
[Image: 86251a37e635a21aea7eb7e014b0d820.gif]
That's actually a very good tutorial!
Also now that AeonHack Added this feature at ThemeBase 1.5.3 its getting better and better!
Nice tutorial Tedd :) glad to see you making the effort again <3
Nice one tedd, Awesome share and an even better tutorial +10 for not supplying full code, It's much better to teach :)
Erhm.. Dont hate me if i ask for something stupid now..!

Is it only possible to do like .red or .green, or is it possible to make a user difined color like in html (black) etc.?
(Oct 12, 2011 01:40 AM)Fuffu Wrote:  Erhm.. Dont hate me if i ask for something stupid now..!

Is it only possible to do like .red or .green, or is it possible to make a user difined color like in html (black) etc.?

You may do any of the following:

Code
Color.Red, Color.Blue 'and things like that

Color.FromARGB(255, 255, 255) 'This is RGB

Color.FromARGB(120, 0, 0, 0) 'This is black at 120 opacity

Color.FromARGB(120, Color.Red) 'This is Color.Red at 120 opacity

As far as an actual HTML color code goes, you would have to build a script to convert it to RGB.
[Image: 86251a37e635a21aea7eb7e014b0d820.gif]


Possibly Related Threads...
Thread / Author Replies Views Last Post
[.NET] by ๖ۣۜMephobiaNov 14, 2025 07:54 PM 171 21,487 Nov 14, 2025 07:54 PM
Last Post: ProxyLand
[.NET] by QuobiAug 6, 2022 02:23 PM 0 407 Aug 6, 2022 02:23 PM
Last Post: Quobi
[.NET] by PolarisGangJun 21, 2022 10:09 AM 1 353 Jun 21, 2022 10:09 AM
Last Post: gigajew