Date: 4/21/20
Using W10/64 and VS 2019 Community.
I am trying to do a simple 3 color horizontal gradient fill. I was able to trap the error but not find out exactly the problem. A breakpoint on the problem line indicated colorBlend to be correct. Here is the code. I would appreciate any help with this.
Using W10/64 and VS 2019 Community.
I am trying to do a simple 3 color horizontal gradient fill. I was able to trap the error but not find out exactly the problem. A breakpoint on the problem line indicated colorBlend to be correct. Here is the code. I would appreciate any help with this.
Code:
Rectangle myRectangle = new Rectangle ( x3, y1, x4 - x3, y2 - y1 + 1 );
// fillColor is any arbitrary Color. Eg Color.Blue
Color[] myColors = { fillColor, Color.White, fillColor };
float[] myPositions = { 0f, 0.5f, 1f };
ColorBlend colorBlend = new ColorBlend ();
colorBlend.Colors = myColors;
colorBlend.Positions = myPositions;
LinearGradientBrush linGrBrush =
new LinearGradientBrush ( myRectangle,
fillColor,
fillColor, LinearGradientMode.Horizontal );
// failure is at the following line. VS gives this error:
// System.ArgumentException: Property must be set to
// a valid ColorBlend object to use interpolation
// colors. ColorBlend objects must be constructed
// with the same number of positions and color
// values. Positions must be between 0.0 and 1.0, 1.0
// indicating the last element in the array. at
// System.Drawing.Drawing2D.LinearGradientBrush._GetI
// nterpolationColors() indicating the last element in
// the array. at System.Drawing.Drawing2D.LinearGradientBrush
// ._GetInterpolationColors()
linGrBrush.InterpolationColors = colorBlend; // error here
graphicsObject.FillRectangle ( linGrBrush, myRectangle );
Comment