# How do I draw transparent polygons?

• 01-28-2010
Sfel
How do I draw transparent polygons?
Hello,

Suppose I have two Point / PointF arrays P1 and P2. How can I draw two polygons on a panel, one from P1 and the other from P2, such that the two are transparent? Meaning, in case they overlap, I can also see the one that's under.

From what I've seen on searches I have to use DirectX directly or something like that, but I haven't seen any clear examples. Could someone provide an example?
• 01-28-2010
Salem
So what functions do you use to draw opaque polygons?

Look through the documentation for say "alpha". If you're familiar with RGB for setting a colour, then RGBA is the advanced form.
Eg.
RGB=( 255, 0, 0 ); // red

then
RGBA=( 255, 0, 0, 255 ); // solid red
RGBA=( 255, 0, 0, 128 ); // semi-transparent red
• 01-28-2010
theoobe
Well a simple solution for you would be to alter the color's opacity by setting the color's alpha value to something lower than 255. Example:

Code:

```using System.Drawing; using System.Windows.Forms; namespace WindowsFormsApplication1 {     public partial class Form1 : Form     {         public Form1()         {             InitializeComponent();         }         private void Form1_Paint(object sender, PaintEventArgs e)         {             Graphics g = e.Graphics;             g.FillPolygon(new SolidBrush(Color2Transparent(Color.Red)), new Point[] {                 new Point(10, 10),                 new Point(100, 100),                 new Point(10, 110)             });             g.FillPolygon(new SolidBrush(Color2Transparent(Color.Blue)), new Point[] {                 new Point(50, 10),                 new Point(150, 100),                 new Point(60, 110)             });         }         private Color Color2Transparent(Color c)         {             return Color.FromArgb(128, c.R, c.G, c.B); // setting opacity to about 50%         }     } }```
The result will look like this: http://i45.tinypic.com/9lj3hx.jpg
• 01-28-2010
theoobe
Sorry Salem, I didn't see your post when I starting writing mine.
• 01-28-2010
Sfel
I was using the FillPolygon function to draw opaque polygons. I didn't know about the FromArgb function, that is what I was looking for.

Thank you both!