How Apply Transparency to a Rectangle

Jose Manuel Benitez 2 years ago updated by Андрей Ринас2 (ATAS developer) 2 years ago 1

When create a DrawingRectangle object the background colour is defined by a System.Drawing.SolidBrush object but this is a solid colour and when it’s shown on the chart it doesn't possible to see other objects behind the rectangle. I would like to apply some transparency in order to see the these objects behind. Does anybody know how to apply transparency to a rectangle created as DrawingRectangle object?


To draw transparency objects you need to set alpha channel in the color.

Here is a sample how to apply it to a rectangle(with alpha level=100):

var color = Color.FromArgb(100, Color.Blue);
var width = 4;
var pen=new RenderPen(color,width);
context.DrawRectangle(pen, new Rectangle(0, 0, 100, 100));

Alpha level couldn't be more than 255 and less than 0.