Apply Alpha Blending Using Appearances
- 3 minutes to read
The Alpha Blending feature allows you to enhance the appearance of a vertical grid control by painting its elements using transparent brushes and pens. This topic explains how to implement the Alpha Blending feature by customizing the appearance settings used to paint the vertical grid elements.
Appearances and Alpha Blending
The vertical grid controls (VGridControl and PropertyGridControl) allow you to customize the appearance of the following.
- Various elements of the controls. For instance, you can change the appearance of row headers, category rows, cells, etc.
- All cells in specific rows. See the Customizing Appearances of Individual Rows topic more information.
- Individual cells. The way in which this can be done is described in the Customizing Appearances of Individual Cells topic.
Example
This example shows how to set the transparency for row headers and empty space within a VGridControl. As a result, the vertical grid’s background image will be partially visible.
Follow the steps below.
Select the control to display its properties within the Properties window and assign an image to its BackgroundImage property.
- Invoke the VerticalGrid Designer and switch to the Appearances page.
Select the Empty appearance in the Appearances list and set its BackColor property to Transparent. This will make the vertical grid’s background image visible in the control area that is not occupied by any elements.
Select the RowHeaderPanel item in the Appearances list (this appearance item corresponds to non-focused row headers) and set its background color to a semi-transparent color: (150, 209, 157, 139).
Select the FocusedRow item in the Appearances list (this appearance item corresponds to the focused row header) and set its background color to another semi-transparent color: (150, 255, 177, 179).
Run the application. The image below shows the result.
Runtime Example
All of the above can also be done via code, as shown in the sample code below. The code is enclosed in calls to the VGridControlBase.BeginUpdate and VGridControlBase.EndUpdate methods to prevent the vertical grid from being updated numerous times.
// Lock the control to prevent it from being repainted multiple times.
vGridControl1.BeginUpdate();
try {
// Specify the vertical grid's background image.
vGridControl1.BackgroundImage = Image.FromFile("c:\\Images\\bg6.png");
// Modify the appearance settings used to paint the Empty region.
vGridControl1.Appearance.Empty.BackColor = Color.Transparent;
// Modify the appearance settings of row headers.
vGridControl1.Appearance.RowHeaderPanel.BackColor = Color.FromArgb(150, 209, 157, 139);
vGridControl1.Appearance.FocusedRow.BackColor = Color.FromArgb(150, 255, 177, 179);
}
finally {
// Unlock the control and repaint it with respect to the changes made.
vGridControl1.EndUpdate();
}