Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Why not System.Drawing.Brush as property?
Message
General information
Forum:
ASP.NET
Category:
Class design
Miscellaneous
Thread ID:
01023287
Message ID:
01023371
Views:
11
This message has been marked as a message which has helped to the initial question of the thread.
Einar,

The designer has no default UITypeEditor means for editing a Brush property so you would need to implement this and the necessary TypeConverter. You can cache the brush but need to create a default instance in your constructor, however if you are using this as the basis for end-user colour selection then use a Color instead and wrap your brush creation in your OnPaint inside a Using block.
using (LinearGradientBrush brush1 = new LinearGradientBrush(GradientRectangle, StartColor, EndColor, 90f))
{
   e.Graphics.FillRectangle(brush1, GradientRectangle);
}
The .NET Brush is a wrapper around a GDI/GDI+ unmanaged resource and really should be treated as something in limited supply. By applying the creation of the brush inside the using statement you will get the benefit of having code generated by the compiler to automatically call Dispose on classes that implement the IDisposable interface to release any unmanaged resources inside a try...catch block.

Regards
Neil
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform