Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Why not System.Drawing.Brush as property?
Message
De
15/06/2005 05:24:26
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
Information générale
Forum:
ASP.NET
Catégorie:
Conception classe
Divers
Thread ID:
01023287
Message ID:
01023372
Vues:
13
This message has been marked as a message which has helped to the initial question of the thread.
>Is there anything that prevent me from using System.Drawing.Brush as a property in a custom control?
>
>private System.Drawing.Brush _LightBrush;
>public System.Drawing.Brush LightBrush
>{
>	get{return _LightBrush;}
>	set{_LightBrush = value;}
>}
>
>then in the OnPaint() event I use the brush to fill a region.
>
>I do not receive a compile time error but I do catch an exception at run time (it is an ArgumentNullException stating that value can not be null). I would like to change the property to a different value in the designer but I can't because it is disabled ("grayed out").
>
>I would like the user of my control (that would be me) to be able to select the brush color at design time in the property sheet.
>
>I tried making the property of type System.Drawing.Color and then try to somehow declare a brush with that color in the OnPaint() event, but I am kind of stuck on that one.
>
>Also something that might help me if I could remember how to assign a default value to a property.
>
>Any help would be appreciated.
>
>Thanks,
>Einar
>
>UPDATE:
>Using DefaultValue:
>
>DefaultValue(System.Drawing.Brushes.Cyan)
>
>Gives me the following compile time error:
>
>An attribute argument must be a constant expression, typeof expression or array creation expression.
>
>System.Drawing.Brushes.Cyan seems pretty darn constant to me.

Einar,
I'm not exactly sure but trying anyway:) Brush is an abstract class that can't be instantiated. Might that be the problem and you should instead say use SolidBrush.
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform