Search code examples
c#user-controlswindows-mobilewindows-cesmart-device

Inherited control in Smart Device (Windows CE) solution of Visual Studio 2008 doesn't work properly


I have a design time problem when I inherit a UserControl in Smart Device (Windows CE) solution of Visual studio 2008. Assume that I have a class like this:

public class MyLabel:Label
{
//Do nothing at all
}

When I put MyLabel in a Form, it doesn't display its text in design time, but at run-time it's working properly. So the problem is Visual Studio Label is working correctly but if I just inherit from it, it doesn't display its text in design time.

I have read some articles in MSDN like this link Creating and Migrating Smart Device Custom Controls by Using Visual Studio 2005 and other websites about how to design a UserControl in Smart Device solution but it was too perfect and had a lot of code in it that confused me. I just want MyLabel to show its text properly in design time, I don't want a perfect UserControl. So if you have experienced my problem please share your solution.


Solution

  • It's working for me. Is it possible there is more logic in your MyLabel class that you've excluded for brevity that is causing the problem?

    Here are the steps I followed:

    1. Create a new C# Smart Device project for Windows Mobile 5 using Visual Studio 2008.
    2. Add New Class > MyLabel.
    3. Copy/Paste the code from your question.
    4. Build the Solution.
    5. Drag the MyLabel control from the toolbox to the form.
    6. Change the MyLabel.Text property to "Hello, World!".
    7. The text is showing "Hello, World!" in design mode and at runtime.

    Sometimes you have to add an XMTA file to help the designer, but I don't think this is one of those cases.

    If you're trying to do your own drawing then that is something you'll have problems with as mentioned by the comment responses to your question.