Custom control won't draw on form

  • Thread starter Thread starter Brad Wood
  • Start date Start date
B

Brad Wood

I need a tag property added to a Button control. I read about
"extenders" to add properties to existing controls, but like so much
else, this is not possible in the CF.
So I was forced to make a custom control that would extend the button.
I compiled this and it works fine in a standard winforms project.

I read in a prior post that adding the following attribute will allow a
control to work with a smart device project:
#if NETCFDESIGNTIME
[
ToolboxItemFilter("System.CF.Windows.Forms",
ToolboxItemFilterType.Custom),
ToolboxItemFilter("NETCF", ToolboxItemFilterType.Require)
]
#endif
After compiling my library with this conditional attribute, the control
does appear enabled when I have a CF project open, however, it won't
draw on the form.

I have absolutely no clue what is causing this...
 
Take a look at some of the online tutorials. Just adding the code isn't
enough, you must compile both a designer version and a runtime version of
the control.

-Chris
 
Take a look at some of the online tutorials. Just adding the code isn't
enough, you must compile both a designer version and a runtime version of
the control.

I don't believe there are any online tutorials. I see an article
titled, "Creating custom controls for the .Net Compact Framework" by
Chris Kinsman referenced all over the place but it no longer exists.

I was able to download an example project, "Color Button" from
codeproject.com. I examined the project and did my best to mimic it. I
had to create new dll projects and remove the default references and
replace them with CF references (there doesn't seem to be any way to
create a new CF dll).

Anyway, after getting my run and design time projects looking just like
the sample and copying them to the "Windows CE" and "Windows
CE\Designer" directories respectively, still the component didn't work
(this time it appeared disabled on the tool palette).

I wish I knew where to find some information on how to accomplish this...
 
What is the class name of your control? I've gotten strange errors through
the designer when trying to add a control named with the same name as a
System.Windows.Forms control. Hence, in the OpenNETCF SDF, the button
control is named ButtonEx.
 
Hmmm. That shouldn't cause a conflict. But I thought it was worth checking.
I had a look at your source files and a couple things stand out.

(1)
Is your runtime assembly named "CF_Controls.dll" and located in the "<VS.Net
2003 install dir>\CompactFrameworkSDK\v1.0.5000\Windows CE" directory? And
of course the design-time assembly, which you have compiled against the CF
designer assemblies and have added to the ToolBox, is in the "<VS.Net 2003
install dir>\CompactFrameworkSDK\v1.0.5000\Windows CE\Designer" directory?

(2)
AFAIK, you shouldn't need this section. It is for components only.
#if NETCFDESIGNTIME
[
ToolboxItemFilter("System.CF.Windows.Forms", ToolboxItemFilterType.Custom),
ToolboxItemFilter("NETCF", ToolboxItemFilterType.Require)
]
#endif

(3)
You may run into problems with your property as well because when you
compile against the desktop Fx the Control class has a Tag property. In
addition, this Tag property is of type Object not Byte. So you may want to
change the name of your property as well. Just a thought.
 
Tim said:
Is your runtime assembly named "CF_Controls.dll" and located in the "<VS.Net
2003 install dir>\CompactFrameworkSDK\v1.0.5000\Windows CE" directory? And
of course the design-time assembly, which you have compiled against the CF
designer assemblies and have added to the ToolBox, is in the "<VS.Net 2003
install dir>\CompactFrameworkSDK\v1.0.5000\Windows CE\Designer" directory?
Yes.

AFAIK, you shouldn't need this section. It is for components only.
#if NETCFDESIGNTIME
[
ToolboxItemFilter("System.CF.Windows.Forms", ToolboxItemFilterType.Custom),
ToolboxItemFilter("NETCF", ToolboxItemFilterType.Require)
]
#endif

I thought the same thing, but if I compile w/o this, my control appears
on the tool pallette disabled.
You may run into problems with your property as well because when you
compile against the desktop Fx the Control class has a Tag property. In
addition, this Tag property is of type Object not Byte. So you may want to
change the name of your property as well. Just a thought.

No such luck, but thanks!
 
Tim said:
(1) Using the contents of the attached zip file, I build the output to an
assembly named "MyCompany.Windows.Forms.dll".

(2) Copy the "MyCompany.Windows.Forms.dll" assembly to the "<VS.Net 2003
install dir>\CompactFrameworkSDK\v1.0.5000\Windows CE" directory.

(3) Then I run the "Visual Studio .NET 2003 Command Prompt".

(4) Locate and call a batch file that contains the following command line -
csc /noconfig /define:DESIGN /target:library
/out:MyCompany.Windows.Forms.Design.dll AssemblyInfo.cs TagButton.cs
/r:.\System.CF.Design.dll /r:.\System.CF.Windows.Forms.dll
/r:System.Windows.Forms.dll /r:System.dll /nowarn:1595
*Ensure that the AssemblyInfo.cs, TagButton.cs, and CF design-time assembly
files are referenced properly within the command line.
When I tried to build referencing the units in this order I get an
error, "you must add a reference to assembly 'System.Windows.Forms'". I
had to reference the CF units (system and system.windows.forms) first to
get the project to build. Even though this is a design time project, I
reference those two files from the "Windows CE" directory, correct?
That seems strange.
(5) Copy the "MyCompany.Windows.Forms.Design.dll" assembly to the "<VS.Net
2003 install dir>\CompactFrameworkSDK\v1.0.5000\Windows CE\Designer"
directory.

Now create a test application and add the control to the ToolBox by located
the design-time version (MyCompany.Windows.Forms.Design.dll).

After doing this, the control appears disabled in the tool palette. I
would think it is related to the Windows CE dlls I am referencing..??..
 
Wait, this is a Full Framework project? There's the problem. The project
needs to be a Smart Device project.
 
Steps 1 and 2 are related to the runtime version of the assembly and the
rest of the steps are related to the design-time version. The design-time
version should reference the desktop assemblies as this is where the
assembly is going to be used - through the VS.Net designer on a desktop
computer.
 
Wait, this is a Full Framework project? There's the problem. The project
needs to be a Smart Device project.

The run time project is a smart device project, and the design time
command line build references some units in the Windows CE\Designer
directory (like system.CF.Design) and others in the Windows CE directory
(like system). Is this incorrect?
 
Tim said:
Steps 1 and 2 are related to the runtime version of the assembly and the
rest of the steps are related to the design-time version. The design-time
version should reference the desktop assemblies as this is where the
assembly is going to be used - through the VS.Net designer on a desktop
computer.
That occurred to me in the mean time. When I referenced the full
framework versions of system and windows.forms, the result was the same.
I still could not build unless I referenced those assemblies *before*
the compact framework design assemblies whereas your original batch file
example showed them *after* - is there something to that?
 
Yeah, I *think* the order is important here. Specify the CF designer
assemblies first and the full fx assemblies last. The /nowarn switch is
important here too. And ensure that the "/define:DESIGN" specifies the
proper constant that you used - I think for you it was NETCFDESIGNTIME.
Maybe if you zip and post your entire control solution or project I can take
a look at it when I get a chance.
 
Tim said:
Here are the steps that you should take to see if the attached solution
works for you.

That did the trick. I don't know which specific action fixed my problem
(the only thing I hadn't done previously was to reset the toolbox).

Thanks much.
 
Back
Top