custom CF control editor's PaintValue conflict of Drawing assembly

A

Anatoly

All,

I have a custom control for CF, which has some custom designers and
editors. The editors use PaintValue to represent some of the values
graphically. The paintValue doesn't work at design time if the Design
project references System.CF.Drawing before System.Drawing. If I
switch their order in the project file, then the drawing starts to
work (if I already have the control dropped onto the project), but the
the Visual Studio doesn't properly drop the custom control onto the CF
Form anymore, it produces errors like Invalid Cast or cannot transform
object for target, etc.

The editor class looks like this:

public class GradeEditor : UITypeEditor
{
public override bool GetPaintValueSupported(ITypeDescriptorContext
context)
{
// if I put a messagebox call here, it does show that this does get
called.
return true;
}

public override void PaintValue(PaintValueEventArgs pe)
{
// NOTE: I verify that PaintValue is called by this messagebox
below
System.Windows.Forms.MessageBox.Show("PaintValue called");
String bmpName = null;
Grade g = (Grade)pe.Value;
if (g.Value > 80)
{
bmpName = "best.bmp";
}
else if (g.Value > 60)
{
bmpName = "ok.bmp";
}
else
{
bmpName = "bad.bmp";
}

Bitmap b = new Bitmap(typeof(GradeEditor), bmpName);

pe.Graphics.DrawImage(b, pe.Bounds);

b.Dispose();
}
}

The editor is references by a statement like this:


[Editor(typeof(GradeEditor),
typeof(System.Drawing.Design.UITypeEditor))]
[TypeConverter(typeof(GradeConverter))]
public struct Grade
{
private int grade;

public Grade(int grade)
{
this.grade = grade;
}

public int Value
{
get
{
return grade;
}
}
}


internal class GradeConverter : TypeConverter
{
[... snip ... - standard code]

}

So somehow, the editor gets the call to GetPaintValueSupported, which
returns true, but doesn't call PaintValue after that at all.

This gets fixed by moving the System.Drawing reference in the
Design.<mycontrol>.DLL project up before System.CF.Drawing. But in
turn that prevents the control from properly casting when dropping
onto the target CF Form.


Here is the extract of C# project references section for
Design.<mycontrol>.dll when it actually allows to drop this control
onto a CF Form:

<References>
<Reference Name="System" AssemblyName="System"
HintPath="..\..\..\..\WINNT\Microsoft.NET\Framework\v1.1.4322\System.dll"
/>
<Reference Name="System.Data" AssemblyName="System.Data"
HintPath="..\..\..\..\WINNT\Microsoft.NET\Framework\v1.1.4322\System.Data.dll"
/>
<Reference Name="System.XML" AssemblyName="System.Xml"
HintPath="..\..\..\..\WINNT\Microsoft.NET\Framework\v1.1.4322\System.XML.dll"
/>
<Reference Name="System.CF.Windows.Forms"
AssemblyName="System.CF.Windows.Forms" HintPath="..\..\..\..\Program
Files\Microsoft Visual Studio .NET
2003\CompactFrameworkSDK\v1.0.5000\Windows
CE\Designer\System.CF.Windows.Forms.dll" />
<Reference Name="System.CF.Drawing" AssemblyName="System.CF.Drawing"
HintPath="..\..\..\..\Program Files\Microsoft Visual Studio .NET
2003\CompactFrameworkSDK\v1.0.5000\Windows
CE\Designer\System.CF.Drawing.DLL" />
<Reference Name="System.CF.Design" AssemblyName="System.CF.Design"
HintPath="..\..\..\..\Program Files\Microsoft Visual Studio .NET
2003\CompactFrameworkSDK\v1.0.5000\Windows
CE\Designer\System.CF.Design.dll" />
<Reference Name="System.Windows.Forms"
AssemblyName="System.Windows.Forms"
HintPath="..\..\..\..\WINNT\Microsoft.NET\Framework\v1.1.4322\System.Windows.Forms.dll"
/>
<Reference Name="System.Drawing.Design"
AssemblyName="System.Drawing.Design"
HintPath="..\..\..\WINNT\Microsoft.NET\Framework\v1.1.4322\System.Drawing.Design.dll"
/>
<Reference Name="System.Drawing" AssemblyName="System.Drawing"
HintPath="..\..\..\WINNT\Microsoft.NET\Framework\v1.1.4322\System.Drawing.dll"
/>
<Reference Name="System.Design" AssemblyName="System.Design"
HintPath="..\..\..\WINNT\Microsoft.NET\Framework\v1.1.4322\System.Design.dll"
/>
</References>

(NOTE THAT System.CF.Drawing appears before System.Drawing) - this is
exactly what pevents the Visual Studio at design time to allow the
PaintValue of my editors to work properly.

If I move System.CF.Drawing at the end of the list, like this (see XML
below), then Visual Studio wont allow me to drop this control on a
target CF Form. I know for fact that this would allow the PaintValue
to work, because I had added this control before switching the
references, then re-opened the form hosting solution (control was
already added), and designer perfectly did all PaintValue calls,
however, it wont allow to drop this control onto a new form anymore...

<References>
<Reference Name="System" AssemblyName="System"
HintPath="..\..\..\..\WINNT\Microsoft.NET\Framework\v1.1.4322\System.dll"
/>
<Reference Name="System.Data" AssemblyName="System.Data"
HintPath="..\..\..\..\WINNT\Microsoft.NET\Framework\v1.1.4322\System.Data.dll"
/>
<Reference Name="System.XML" AssemblyName="System.Xml"
HintPath="..\..\..\..\WINNT\Microsoft.NET\Framework\v1.1.4322\System.XML.dll"
/>
<Reference Name="System.CF.Windows.Forms"
AssemblyName="System.CF.Windows.Forms" HintPath="..\..\..\..\Program
Files\Microsoft Visual Studio .NET
2003\CompactFrameworkSDK\v1.0.5000\Windows
CE\Designer\System.CF.Windows.Forms.dll" />
<Reference Name="System.CF.Design" AssemblyName="System.CF.Design"
HintPath="..\..\..\..\Program Files\Microsoft Visual Studio .NET
2003\CompactFrameworkSDK\v1.0.5000\Windows
CE\Designer\System.CF.Design.dll" />
<Reference Name="System.Windows.Forms"
AssemblyName="System.Windows.Forms"
HintPath="..\..\..\..\WINNT\Microsoft.NET\Framework\v1.1.4322\System.Windows.Forms.dll"
/>
<Reference Name="System.Drawing.Design"
AssemblyName="System.Drawing.Design"
HintPath="..\..\..\WINNT\Microsoft.NET\Framework\v1.1.4322\System.Drawing.Design.dll"
/>
<Reference Name="System.Drawing" AssemblyName="System.Drawing"
HintPath="..\..\..\WINNT\Microsoft.NET\Framework\v1.1.4322\System.Drawing.dll"
/>
<Reference Name="System.Design" AssemblyName="System.Design"
HintPath="..\..\..\WINNT\Microsoft.NET\Framework\v1.1.4322\System.Design.dll"
/>
<Reference Name="System.CF.Drawing" AssemblyName="System.CF.Drawing"
HintPath="..\..\..\Program Files\Microsoft Visual Studio .NET
2003\CompactFrameworkSDK\v1.0.5000\Windows
CE\Designer\System.CF.Drawing.DLL" />
</References>


Does any one know how to get out of this situation? - that is to be
able to:
1. Use Custom editor's PaintValue
2. be able to drop this control onto the target CF Form.

(Right now these 2 things cannot be combined). I either can't use the
control, or PaintValue doesn't get called


Cheers,

Anatoly
 
D

David So [MSFT]

Anatoly,

Could you send me your project for me to investigate?

Thanks,

David
This posting is provided "AS IS" with no warranties, and confers no rights.


--------------------
| From: (e-mail address removed) (Anatoly)
| Newsgroups: microsoft.public.dotnet.framework.compactframework
| Subject: Re: custom CF control editor's PaintValue conflict of Drawing
assembly
| Date: 11 Sep 2003 10:17:24 -0700
| Organization: http://groups.google.com/
| Lines: 1
| Message-ID: <[email protected]>
| References: <[email protected]>
| NNTP-Posting-Host: 205.142.0.75
| Content-Type: text/plain; charset=ISO-8859-1
| Content-Transfer-Encoding: 8bit
| X-Trace: posting.google.com 1063300645 1651 127.0.0.1 (11 Sep 2003
17:17:25 GMT)
| X-Complaints-To: (e-mail address removed)
| NNTP-Posting-Date: 11 Sep 2003 17:17:25 GMT
| Path:
cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfeed00.sul.t-online.de!t-onlin
e.de!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!sn-xit-03!sn-xit-06!sn-
xit-09!supernews.com!postnews1.google.com!not-for-mail
| Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.framework.compactframework:33358
| X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework
|
| may be someone at MSFT have an answer to this?
|
 
B

Benjamin Wulfe

The problem is that the PainValueEventArgs is defined in
System.CF.Drawing.dll.
You can fix this by moving your editor to a different assembly whose
reference resolution resolves to System.Drawing.dll first. If you do this,
you can not reference System.CF.* in this new assembly at all -- only
desktop types. It makes life a lot simpler when writing an editor. To set
or edit return values -- use reflection.
Make sure this assembly is installed in the GAC. Let me know if there are
issues.

-Ben

This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
| From: (e-mail address removed) (Anatoly)
| Newsgroups: microsoft.public.dotnet.framework.compactframework
| Subject: Re: custom CF control editor's PaintValue conflict of Drawing
assembly
| Date: 11 Sep 2003 10:17:24 -0700
| Organization: http://groups.google.com/
| Lines: 1
| Message-ID: <[email protected]>
| References: <[email protected]>
| NNTP-Posting-Host: 205.142.0.75
| Content-Type: text/plain; charset=ISO-8859-1
| Content-Transfer-Encoding: 8bit
| X-Trace: posting.google.com 1063300645 1651 127.0.0.1 (11 Sep 2003
17:17:25 GMT)
| X-Complaints-To: (e-mail address removed)
| NNTP-Posting-Date: 11 Sep 2003 17:17:25 GMT
| Path:
cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfeed00.sul.t-online.de!t-onlin
e.de!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!sn-xit-03!sn-xit-06!sn-
xit-09!supernews.com!postnews1.google.com!not-for-mail
| Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.framework.compactframework:33358
| X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework
|
| may be someone at MSFT have an answer to this?
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top