We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Unable to change gradient panel colors at run time

Thread ID:





3291 Mar 12,2003 02:51 AM UTC Mar 31,2003 06:20 PM UTC WinForms 3
Tags: Tools
Charles Wolfersberger
Asked On March 12, 2003 02:51 AM UTC

How can you change the colors in a gradient panel at run time? I have tried the following so far with no success: gradPanel.GradientColors.SetValue(Color.Red, 0) gradPanel.GradientColors(0) = Color.Red Thanks Charles

Davis Jebaraj [Syncfusion]
Replied On March 14, 2003 09:34 PM UTC

Hi Charles, Setting the GradientColors property again with just the color you want to change works: this.gradientPanel1.GradientColors = new System.Drawing.Color[] {Color.AliceBlue , this.gradientPanel1.GradientColors[1]}; The above case has a GradientPanel with 2 colors and I am changing the first one alone. Regards, Davis

Charles Wolfersberger
Replied On March 15, 2003 01:07 AM UTC

Thanks for the help! One more question, though. I have a gradient panel with three colors. When I change any one of the gradient colors (using the code you provided), the panel's gradient color array automatically changes back to a 2-color array/gradient. (The panel's color array is originally set to three colors through the panel's property page.) Is there a way to maintain the gradient panel's original color array legnth and manipulate the colors in such an array? Thanks Charles

Charles Wolfersberger
Replied On March 31, 2003 06:20 PM UTC

Never mind. I brushed up on my array skills and figured it out. In VB.Net the following sets the gradient for multiple colors: Dim arrColorArray() As System.Drawing.Color ={Color.Red, Color.Green, Color.Blue, ...} GradientPanel.GradientColors() = arrColorArray If you set individual colors in the GradientPanel's GradientColor array property AND the GradientColor array holds more than two colors, then you cannot set individual colors within the GradientColor array. The reason is that any time you set a color in the GradientColor's array, the control automatically resets the array to hold two elements(colors) regardless of how many items you originally add to the GradientColor array. Thus, if you write something like this (like I did)--GradientPanel.GradientColors(2) = Color.Red--you will get an out of bounds error when writing to the array because the control automatically reset the array to hold two elements. The efficient solution to this problem seem to be creating a seperate color array (Dim arrColors(2) As Color) and then, whenever you change a color in that array, simply update the GradientColors array (GradientColors() = arrColors). Hope this is helpful! Charles


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

or the page will be automatically redirected to sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon