PC Review


Reply
Thread Tools Rate Thread

Custom control won't draw on form

 
 
Brad Wood
Guest
Posts: n/a
 
      15th Dec 2004
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...
 
Reply With Quote
 
 
 
 
Guest
Posts: n/a
 
      16th Dec 2004
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


"Brad Wood" <bradley_.wood_@ndsu_.edu> wrote in message
news:(E-Mail Removed)...
>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...



 
Reply With Quote
 
Brad Wood
Guest
Posts: n/a
 
      16th Dec 2004
<ctacke/> wrote:
> 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...
 
Reply With Quote
 
Tim Wilson
Guest
Posts: n/a
 
      16th Dec 2004
The "ToolboxItemFilter" attribute is required for adding custom components
(no-UI) to the ToolBox. What you need to use for a control is the
"System.CF.Design.RuntimeAssemblyAttribute" attribute. The article linked
below should help.
http://www.intelliprog.com/articles/index.html

--
Tim Wilson
..Net Compact Framework MVP

"Brad Wood" <bradley_.wood_@ndsu_.edu> wrote in message
news:(E-Mail Removed)...
> <ctacke/> wrote:
> > 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...



 
Reply With Quote
 
Chris Tacke, eMVP
Guest
Posts: n/a
 
      16th Dec 2004
These all appear to be online tutorials, and relevant to what you're after.

http://www.intelliprog.com/articles/index.html
http://msdn.microsoft.com/library/de...ad11272002.asp
http://msdn.microsoft.com/library/de...omctrlssde.asp

--
<ctacke/>
www.OpenNETCF.org
Your CF searches start and end here


"Brad Wood" <bradley_.wood_@ndsu_.edu> wrote in message
news:(E-Mail Removed)...
> <ctacke/> wrote:
>> 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...



 
Reply With Quote
 
Tim Wilson
Guest
Posts: n/a
 
      17th Dec 2004
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.

--
Tim Wilson
..Net Compact Framework MVP

"Brad Wood" <bradley_.wood_@ndsu_.edu> wrote in message
news:%(E-Mail Removed)...
> I've read all the articles, but still no joy. I was able to get the
> component on my pallette enabled OK, but now when I try to add it to a
> form I get the message, "Object type cannot be converted to target
> type." I know it has nothing to do with my single simple property added
> to the Button component because it worked fine when I compiled and used
> it with a regular .net project.
>
> Here is what I tried (one of the articles referenced mentioned that you
> should use some batch file to compile the design time dll, but I know
> that is not necessary because I was able to compile the "Colour Button"
> and use it fine; besides, I can't find the batch file even in the places
> mentioned by newsgroups):
>
> <run time project>
> - Regular smart device project with "output type" changed to class
> library.
> - see code files below
> </run time project>
>
> <design time project>
> - regular .net class library
> - references regular .net system and system.windows.forms
> - also references system.cf.design, system.cf.drawing, and
> system.cf.windows.forms
> - added conditional compile "NETCFDESIGNTIME"
> - see code files below
> </design time project>
>
> <code files>
> - assemblyInfo: contains AssemblyVersion attribute to keep version
> number constant
> - TagButton.cs: contains System.CF.Design.RuntimeAssembly attribute
> to link design and run time assemblies
> - conditionally includes System.ComponentModel
> </code files>
>
> I've attached the exceedingly simple code files in case somebody has an
> idea what is wrong...
>



 
Reply With Quote
 
Brad Wood
Guest
Posts: n/a
 
      17th Dec 2004
Tim Wilson wrote:
> What is the class name of your control?


It's named TagButton.
 
Reply With Quote
 
Tim Wilson
Guest
Posts: n/a
 
      17th Dec 2004
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 Wilson
..Net Compact Framework MVP

"Brad Wood" <bradley_.wood_@ndsu_.edu> wrote in message
news:(E-Mail Removed)...
> Tim Wilson wrote:
> > What is the class name of your control?

>
> It's named TagButton.



 
Reply With Quote
 
Brad Wood
Guest
Posts: n/a
 
      17th Dec 2004
Tim Wilson wrote:
> 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!

 
Reply With Quote
 
Brad Wood
Guest
Posts: n/a
 
      17th Dec 2004
Tim Wilson wrote:
> (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 /defineESIGN /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..??..
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Not to draw when my custom control is not visible. Sin Jeong-hun Microsoft C# .NET 0 13th May 2008 03:40 PM
Re: After creating custom container control, control cannot be added to form Michael Nemtsev [MVP] Microsoft C# .NET 1 14th Nov 2007 12:48 PM
How do you access a control property of a main form from a custom user control? forest demon Microsoft C# .NET 6 22nd Aug 2007 11:36 PM
Why must I paint the form background for an owner-draw control? Tim Crews Microsoft Dot NET Framework Forms 27 14th Oct 2004 07:21 AM
Make control draw on top of other form JayG Microsoft Dot NET Framework Forms 0 20th Nov 2003 04:38 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:56 AM.