Here's an example:
public MainForm()
{
InitializeComponent();
LinearGradientBrush brush = new LinearGradientBrush(new Rectangle(0,0,100,100),Color.Blue, Color.White,angle:0);
brush.WrapMode = WrapMode.Tile; // OK
brush.WrapMode = WrapMode.Clamp; // Causes Unhandled exception alert, offering break
}
In the VS2008 output window this shows:
A first chance exception of type 'System.ArgumentException' occurred in System.Drawing.dll Additional information: Parameter is not valid.
(pic http://i.imgur.com/nM2oNm1.png)
This is on Windows 7.
Documentation here https://msdn.microsoft.com/en-us/library/vstudio/system.drawing.drawing2d.lineargradientbrush.wrapmode(v=vs.90).aspx
confirms LinearGradientBrush.WrapMode accepts a WrapMode
"Gets or sets a WrapMode enumeration that indicates the wrap mode for this LinearGradientBrush."
and this https://msdn.microsoft.com/en-us/library/vstudio/system.drawing.drawing2d.wrapmode(v=vs.90).aspx
confirms that WrapMode.Clamp is valid for gradient:
"Clamp The texture or gradient is not tiled."
I can confirm this with VS2015 on Windows 8.1.
This looks like a bug to me, as Clamp
i.e. untiled continuation with, probably the last color would be quite useful.
You can try to workaround with InterpolationColors
but that requires some knowledge of the sizes to fill..
See here and espcially here for code examples for using InterpolationColors
Update: Lars' idea looks also very interesting: Create a tile with the LinearGradientBrush
and then use it with a TextureBrush
..
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With