This forum contains outdated content and is available for reading only. Please contact technical support if you have any questions.

Set gradient color in multilayer objects

Hello..
I would like to give gradient color to mulilayer object's fill color & pen color (Objcts-Ellips,Rectangle, Line,text and polygon) is it possible? pls help me with sample codes....
Hello,

Here is the code snippet which illustrates how to set gradient color for rectangle vector object:
Aurigma.GraphicsMill.WinControls.RectangleVObject rectangle = new Aurigma.GraphicsMill.WinControls.RectangleVObject(0F, 0F,multiLayerViewer1.WorkspaceWidth/10, multiLayerViewer1.WorkspaceHeight/10);
//Modify stroke and fill parameters
rectangle.Pen = new System.Drawing.Pen(System.Drawing.Color.BlanchedAlmond, 10F);
//Fill gradient 
rectangle.Brush = new System.Drawing.Drawing2D.LinearGradientBrush(new Point(0, 10),new Point(200, 10), System.Drawing.Color.Wheat, System.Drawing.Color.Black);
//Add the rectangle to a layer
multiLayerViewer1.Layers[0].VObjects.Add(rectangle);
Thanx.. its pretty good... but, i did not able to set pen color as gradient color. is it possible? pls help me..
Hi,

It is possible too:

...
using (Brush aGradientBrush = new System.Drawing.Drawing2D.LinearGradientBrush(new Point(0, 10), new Point(200, 10), Color.Blue, Color.Red))
  rectangle.Pen = new System.Drawing.Pen(aGradientBrush, 10F);
...
Thanx.... Is it possible to apply gradient color to multilayer image objects? how? pls help me...
Hi,

Sorry, but it is impossible. Pen and brush use standard LinearGradientBrush class to set the gradient color. Unfortunately, there is no way to apply it to ImageVObject of Graphics Mill.
I am using following code to apply gradient color in multilayer background object's color. but it shows error.
Using (Brush aGradientBrush = new System.Drawing.Drawing2D.LinearGradientBrush(new Point(0, 10), new Point(200, 10), Color.Blue, Color.Red))
background.Color = new System.Drawing.Pen(aGradientBrush).Color;

How can i solve this? pls help me ....

.
Hello,

Could you please post the error details? Also, please share more code snippet with me since it is not quite clear what the background is.
Hello.
background is "SolidBackgroundVObject", how can i set the gradient color for this object ?

error of above code:
System.ArgumentException: Parameter is not valid. at System.Drawing.Pen.get_Color()
Okay, thank you for the details. I checked it, and confirm that it is impossible to set gradient color of SolidBackgroundVObject. I recommend you to use lock RectangleVObject as a background, and set the gradient color in the way described above of this thread.
I have used the code

"using (Brush aGradientBrush = new System.Drawing.Drawing2D.LinearGradientBrush(new Point(0, 10), new Point(200, 10), Color.Blue, Color.Red))
rectangle.Pen = new System.Drawing.Pen(aGradientBrush, 10F);" to make gradient pen color. but its making error with "multiLayerViewer.SaveState()". pls provide me a solution...
Hello,

Please share complete code snippet where the error occurs. I will test it. Also, please provide me with error details.
I attached a sample, you please add a rectangle or ellips to multilayerviewer and change its settings (by changing brush or....).. it will make error... in this, i added the above code for pen. After setting the pen , moving objects making a unhandled exception ....
Hello,

Okay, I tried the sample, and got the error. Unfortunately, here setting gradient color for Pen is impossible. There is Pen is a class of System.Drawing, which has its own Color property. It cannot be gradient color. Therefore, you face the exception.