How to apply transparent color to WinForms GridGroupingControl?
Apply transparent back color
To apply transparent back color to the WinForms Grid Control, you need to create a Derived class that is inherited from the GridGroupingControl. In that derived class, override the OnParentBackColorChanged()and OnPropertyChanged() methods and set the SupportsTransparentBackColor value to true or SetStyle(ControlStyles.SupportsTransparentBackColor, True) .
Overriding the GridGroupingControl:
C#
public class MyGGC : GridGroupingControl { public MyGGC() { //Sets the SupportsTransparentBackColor value. SetStyle(ControlStyles.SupportsTransparentBackColor, true); } protected override void OnParentBackColorChanged(EventArgs e) { base.OnParentBackColorChanged(e); //Sets the BackColor to the Grid. BackColor = Parent.BackColor; } protected override void OnBackColorChanged(EventArgs e) { Console.Out.WriteLine("MyGGC:OnBackColorChanged called"); base.OnBackColorChanged(e); } protected override void OnParentChanged(EventArgs e) { Console.Out.WriteLine("MyGGC:OnParentChanged called"); base.OnParentChanged(e); BackColor = Parent.BackColor; } }
VB
Public Class MyGGC Inherits GridGroupingControl Public Sub New() 'Sets the BackColor to the Grid. SetStyle(ControlStyles.SupportsTransparentBackColor, True) End Sub Protected Overrides Sub OnParentBackColorChanged(ByVal e As EventArgs) MyBase.OnParentBackColorChanged(e) 'Sets the SupportsTransparentBackColor value. BackColor = Parent.BackColor End Sub Protected Overrides Sub OnBackColorChanged(ByVal e As EventArgs) Console.Out.WriteLine("MyGGC:OnBackColorChanged called") MyBase.OnBackColorChanged(e) End Sub Protected Overrides Sub OnParentChanged(ByVal e As EventArgs) Console.Out.WriteLine("MyGGC:OnParentChanged called") MyBase.OnParentChanged(e) BackColor = Parent.BackColor End Sub End Class
Adding custom GridGroupingControl:
In the form InitializeComponent() method, create an instance for the derived GridGroupingControl.
C#
private MyGGC gridGroupingControl1; //In the InitializeComponets(). this.gridGroupingControl1 = new MyGGC();
VB
Private gridGroupingControl1 As MyGGC 'In the InitializeComponets() Me.gridGroupingControl1 = New MyGGC()
Set the TransparentBackColor:
C#
//Sets the BackColor to the Form. this.BackColor = Color.LightBlue; //Allows Transparent Color to the GGC. this.gridGroupingControl1.TableControl.SupportsTransparentBackColor = true; this.gridGroupingControl1.TableControl.BackColor = Color.Transparent; this.gridGroupingControl1.TableModel.Properties.BackgroundColor = Color.Transparent;
VB
'Sets the BackColor to the Form. Me.BackColor = Color.LightBlue 'Sets Transparent Back Color to the GGC. Me.gridGroupingControl1.TableControl.SupportsTransparentBackColor = True Me.gridGroupingControl1.TableControl.BackColor = Color.Transparent Me.gridGroupingControl1.TableModel.Properties.BackgroundColor = Color.Transparent
Figure 1: Transparent color applied to the GGC
Samples:
C#: TransparentColorGGC-CS.zip
VB: TransparentColorGGC-VB.zip
Conclusion
I hope you enjoyed learning on how to apply transparent color to WinForms GridGroupingControl.
You can refer to our WinForms GridGroupingControl feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!