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
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