Adding a gradient to a GoPalette?


#1
How could one add a gradient to a GoPalette shown in a SplitterWindow?

#2

Use the code below as a static function in one of your classes and use it as follows:
myPalette has to be of the type GoPalette.
myPalette.BackgroundImage = imgBrush.GradientRect(myPanel.ClientRectangle,cColors.PanelTop,cColors.PanelBottom);
public Image GradientRect(Rectangle rectangle,Color colStart,Color colEnd)
{
// create the bitmap we will draw to
try
{
Image image = new Bitmap(rectangle.Width,rectangle.Height);

// calculate the half of the stroke width for use later
// create a rectangle that bounds the ellipse we want to draw

// create a Graphics object from the bitmap
using(Graphics graphics = Graphics.FromImage(image))
{
// create a solid color brush
using(LinearGradientBrush fillBrush = new LinearGradientBrush(rectangle,colStart,colEnd,LinearGradientMode.Vertical))
{
// fill the ellipse specified by the
// rectangle calculated above
graphics.FillRectangle(fillBrush,rectangle);
}
/// create a pen
using(Pen pen = new Pen(strokeColor, strokeWidth))
{
// draw the stroke of the ellipse specified by
// the rectangle calculated above
graphics.DrawEllipse(pen, ellipseBound);
}
/
}
//use this line only to test if it worked…
//image.Save(“c:\gradientrect”,ImageFormat.Bmp);
return image;
}
//Fehler abfangen, der Applikation zum Absturz bringen kann,
//tritt auf, wenn Bild in den Hintergrund gebracht wird, z.B. durch Klicken auf
//Desktop-Symbol in der Taskleiste.
catch(Exception ex)
{
return Images.Back;
}
}
}


#3

Using the BackgroundImage property is a reasonable way of producing all kinds of backgrounds.
An alternative is to override the painting of the paper color and background in a subclass of GoView. The advantage of this method is that it produces the same gradient regardless of the view’s DocPosition or DocSize–i.e., no matter how the user is scrolled or zoomed. It also doesn’t require the additional memory of having a Bitmap for the view.
public class GradientView : GoView {
public GradientView() {}
protected override void PaintPaperColor(Graphics g, RectangleF cliprect) {}
protected override void PaintBackgroundDecoration(Graphics g, RectangleF clipRect) {
RectangleF rect = this.DocExtent;
Brush b = new LinearGradientBrush(rect, Color.SteelBlue, Color.LightBlue,
LinearGradientMode.ForwardDiagonal);
g.FillRectangle(b, rect);
b.Dispose();
base.PaintBackgroundDecoration(g, clipRect);
}
}