Merci Rob, j'ai vraiment apprécié votre réponse. En le testant. J'ai trouvé un substitut encore plus simple pour ce dont j'avais besoin. J'espère que vous trouverez cela utile aussi. L'objet Blend vous permet de créer un tableau de positions X% du début à la fin. Vous créez également un tableau correspondant de Pourcentage des couleurs à ce moment-là, par exemple: 0 = une seule couleur & 1 = toutes les autres. J'ai ensuite créé un pinceau qui avait exactement la même hauteur que mon graphique. J'ai ensuite défini la propriété Blend de l'objet Brush to my Blend. Et créé un stylo en utilisant le pinceau. Cela me permet de dessiner la ligne n'importe où une fois, car il a passé la hauteur de ma transition Blend points qu'il a magiquement changé de couleur.
if (enableThresholdColors) { // Color the extreme values a different color
int Threshold = (thresholdValue < 50 ? 100 - thresholdValue : thresholdValue);
float UpperThreshold = ((float) Threshold)/100f;
float LowerThreshold = ((float) 100 - Threshold)/100f;
LinearGradientBrush br = new LinearGradientBrush(new Rectangle(20, bounds.Top, 30, bounds.Height), Plots[0].Pen.Color, colorThreshold, 90);
Blend bl = new Blend();
// --- this colors the Extreme values the same color ---
bl.Factors = new float[] {1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f};
// --- this colors the Extreme values the opposite color & transitions the line ---
// bl.Factors = new float[] {1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f};
bl.Positions = new float[]{0, LowerThreshold, LowerThreshold, UpperThreshold, UpperThreshold, 1.0f};
br.Blend = bl;
// --- for testing - show where the threshold is. ---
// graphics.FillRectangle(br, new Rectangle(50, bounds.Top, 400, bounds.Height));
//---------------------------------------------------------------------------------------
Pen stocPen = new Pen(br, Plots[0].Pen.Width);
stocPen.DashStyle = Plots[0].Pen.DashStyle;
graphics.DrawPath(stocPen, path);
stocPen.Dispose();
br.Dispose();
} else { // Color the entire line all the same color
graphics.DrawPath(Plots[0].Pen, path);
}