Custom Control - InitializeComponent() problem

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi everyone,

I created a custom control using c# and the control is allocated at runtime
and displayed on the screen correctly(emulator). As soon as I had any events
using the designer (not custom events...) I get the following error:

An unhandled exception of type 'System.MissingMethodException' occurred in
ControlLibrary.dll

Example:
....
private void InitializeComponent()
{
//
// ctrlScreenLogin
//
this.Enter += new System.EventHandler(this.ctrlScreenLogin_Enter);
}
....
private void ctrlScreenLogin_Enter(object sender, System.EventArgs e)
{
}
....

What is wrong with my control?

Sylvain Fortin
 
Where is the Enter event defined? Since the Enter event isn't supported in
the current version of the CF you must have defined this event yourself. If
you didn't, and it compiled fine, are you sure that you're using a smart
device project? If you're still unsure, post some more information about
what you're trying to accomplish and what problems you are encountering.
 
Hi Tim,

Thanks for your reply. Actually, my control is located in a .NET class
library which is the reason why I've been able to add this event from the
designer. I replaced it with a Click event and the control is working well.

Question, is there a way to configure my class library for the .NET CF to
insure I wont waste time on things like that in the future? Since I didn't
see it wasn't supported in the documentation when I checked, anyway to
prevent this kind of error in the future would be great.

Thanks for your time Tim,

Regards,

Sylvain Fortin
 
If you use the "Smart Device Application" project template and then choose
to make the project a "Class Library" when prompted, you will be referencing
the Compact Framework assemblies. However, you will need to add a reference
to the System.Windows.Forms assembly and, if necessary, the System.Drawing
assembly as well, depending on what your control is doing. Now when you
compile, your source will be validated against the Compact Framework. The
documentation is shared with the desktop framework documentation and will
say "Supported by the .NET Compact Framework." below the member name if that
particular member is supported. Sometimes the documentation is not as
accurate as it could be though. So the best approach in certain cases like
this is trial and error. It's not always pretty.

If you currently have your control wrapped in a desktop project, then you
may consider creating a device class library project, adding your source
files, adding all necessary references, and compiling against the Compact
Framework.
 
Hi Tim,

Thanks for your reply amd I will consider what I should do in my project (if
it's important or not to be able to use the controls in FULL .NET and CF .NET
and I'll configure my projects that way.

Once again, thanks for your time,

Regards,

Sylvain Fortin
 
If you don't really need a design-time experience for your control then just
compile it against the Compact Framework and it should be retargetable to
the Full Framework automagically. All you need to do is ensure that you're
using properties, methods, etc. that exist in both the Compact and Full
Framework. Keep in mind that when including the CF-based control in your
desktop project it will still want to link to the device version of
System.Windows.Forms, and any other reference that was included when
building the control. Since the device version of System.Windows.Forms will
be a dependency, the compiler may complain that you have things defined in
multiple locations (desktop System.Windows.Forms and device
System.Windows.Forms). So this solution is possible, but not very elegant.
So I would assume that you would want a design-time version of the control
not only to alleviate the raft of warnings that you'll get in this scenario
but also so that the end-developer will have a better visual experience.

In order to create a design-time version of your control that may be
included in the ToolBox of a device project you will need to use a special
attribute and follow some guidelines. Read through the information at the
following links.

http://msdn.microsoft.com/library/d..._evtuv/html/etconcustomcontroldevelopment.asp
http://msdn.microsoft.com/library/d...ngCustomControlForSmartDeviceApplications.asp

Typically controls in the Compact Framework are lighter-weight versions of
their desktop counterparts. So you might consider creating a full framework
control project and a device class library project. You can share the source
between the two projects (when adding the source file into the projects
choose the dropdown arrow on the Open button in the "Add Existing Item"
dialog box and selecting "Link File"), and then isolate desktop and device
specific code blocks using conditional compilation. Then, define the
appropriate conditional compilation constant in the project properties for
the desktop project and for the device project. This will allow you to
target the Full Framework and Compact Framework using the same source base
(but different assemblies), allow you to have a design-time experience for
the end-developer in either case, and also allow you to add lots of
functionality to the desktop version of the control while only supplying the
absolute necessary functionality in the device version to ensure that the
shipped run-time assembly is as small as possible, if desirable.

#if DESKTOP_ONLY
...
#endif

#if DEVICE_ONLY
...
#endif

HTH
 
Back
Top