Back to Devexpress

Implement Alpha Blending via Custom Painting

windowsforms-5667-controls-and-libraries-tree-list-feature-center-appearances-and-look-and-feel-alpha-blending-implement-alpha-blending-via-custom-painting.md

latest2.1 KB
Original Source

Implement Alpha Blending via Custom Painting

  • Jan 15, 2021

Implement Alpha Blending via Custom Painting

You can implement alpha-blending using custom draw events. In this approach, you need to handle specific custom draw events to paint the Tree List’s elements using transparent brushes. This method is the most powerful one, since you can apply transparency to only one part of an element, or use gradient brushes.

The following sample code handles the TreeList.CustomDrawFooter event to paint the summary footer using a linear gradient brush. The starting and ending colors of this brush are transparent.

csharp
using System.Drawing.Drawing2D;
using DevExpress.XtraTreeList;
// ...

private void treeList1_CustomDrawFooter(object sender, CustomDrawEventArgs e) {
   LinearGradientBrush footerBrush = new LinearGradientBrush(e.Bounds, 
      Color.FromArgb(170, Color.Orange), Color.FromArgb(170, Color.DarkGreen), 
      LinearGradientMode.Vertical);

   using(footerBrush) {
      e.Cache.FillRectangle(footerBrush, e.Bounds);
   }

   e.Handled = true;
}
vb
Imports System.Drawing.Drawing2D
Imports DevExpress.XtraTreeList
' ...

Private Sub TreeList1_CustomDrawFooter(ByVal sender As Object, ByVal e As CustomDrawEventArgs) _
Handles TreeList1.CustomDrawFooter
   Dim FooterBrush As New LinearGradientBrush(e.Bounds, Color.FromArgb(170, Color.Orange), _
      Color.FromArgb(170, Color.DarkGreen), LinearGradientMode.Vertical)

   e.Cache.FillRectangle(FooterBrush, e.Bounds)
   FooterBrush.Dispose()

   e.Handled = True
End Sub

The image below shows the result.

See Also

Custom Drawing