[Mono-devel-list] SystemBrushes and SystemPens - resending

Ravindra Kumar rkumar at novell.com
Wed Jan 7 09:24:06 EST 2004


Hi,
Please ignore my previous mail and kindly review the attached patches.
Sorry for the inconvenience.

As I was going through S.D code I came across following statement in
.NET docs,
*************
SystemColors class:
	Remarks: Better performance is achieved through the use of the
SystemPens object or 
	SystemBrushes object rather than creating a new pen or brush
based on a value from 
	the SystemColors object. For example, use SystemBrushes.Control
because it is a 
	brush that already exists, whereas new
SolidBrush(SystemColors.Control) creates a 
	new brush.
**************
Given this remark, I think the current implementation of SystemBrushes
is not correct as we are creating objects whenever a property is
requested. Please find attached my patch for correcting the same. I have
modified SystemPens also.Additionally, I have added support for
"FromSystemColor(Color)" method and few other missing properties in both
of the classes.

I have two issues here,
1. I have noticed that SystemColors vary with theme on Windows.
Therefore, I don't think current implementation of SystemColors is going
to give us proper values, as it has hardcoded values. May be we should
look at some option of getting these values from desktop or we can use
values of windows classic theme(?).
2. On .NET, I have noticed that Pen/Brush color cannot be modified, if
a pen/brush is obtained from SystemPens or SystemBrushes. I get
following exception,

********************************************************
[code]
	Pen pen = SystemPens.ActiveCaptionText;
	Console.WriteLine("color: " + pen.Color);
	pen.Color = Color.Red;
	Console.WriteLine("color: " + pen.Color);
[code]

E:\Projects\Mono\Tests\System.Drawing\new>TestSystemPens.exe
color: Color [ActiveCaptionText]

Unhandled Exception: System.ArgumentException: You may not change this
Pen because
 it does not belong to you.
   at System.Drawing.Pen.set_Color(Color value)
   at MonoTests.System.Drawing.TestSystemPens.Main()
*********************************************************
I don't know how can I achieve this behavior on Mono. Please give me
some idea to get the same behavior.
Please comment on my changes, if I can commit. However, I think if it
is not possible to achieve this behavior on Mono, existing
implementation of SystemBrushes would be a good choice even for
SystemPens.

Thanks
Ravi
-------------- next part --------------
A non-text attachment was scrubbed...
Name: SystemBrushes.patch2
Type: application/octet-stream
Size: 5993 bytes
Desc: not available
Url : http://lists.ximian.com/pipermail/mono-devel-list/attachments/20040107/90ab8119/attachment.obj 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: SystemPens.patch2
Type: application/octet-stream
Size: 4654 bytes
Desc: not available
Url : http://lists.ximian.com/pipermail/mono-devel-list/attachments/20040107/90ab8119/attachment-0001.obj 


More information about the Mono-devel-list mailing list