custom control vs. designer

X

xtravar

I'm using Visual Studio 2005, Compact Framework 2.0.

I made a custom TextBox control by inheriting the original
System.Windows.Forms.TextBox. I can place my control on forms using
the designer, however, it does not display like the original TextBox
control does - it does not reflect changes to any visual properties
(Text, color, etc).

Is there a smart person out there who can tell me how to inherit from
an existing, functional control that is NOT a UserControl or Form, and
then be able to use the new control *usefully* in the designer, as if
it were the original control?

In other words, I want to be able to do things like "class TextBoxEx :
TextBox" and have the designer treat TextBoxEx as a TextBox and display
it just like a normal TextBox.
 
X

xtravar

I'm sorry, but I've read that before and it is not useful. The project
there clearly inherits from UserControl. I am not inheriting from
UserControl.

I'll try to describe my problem again.

I am creating custom controls. These controls are inherited from the
standard System.Windows.Forms controls.
When I place these on a form in the designer, they do not act like the
controls they inherit from, even if the code body of the new control's
class is empty.
Does anyone know why this is and how I can fix it?
 
T

Tim Wilson

Usually when your smart device custom control does not display and behave as
you think it should within the designer in VS 2005 that implies that you're
missing an attribute that would need to be applied through a xmta file, as
indicated in the link that I provided. However, if you just inherit from a
built in control and supply no additional logic (I'm assuming for testing
purposes) then it should just work. Here is what I did and it worked ok:

(1) Create a Pocket PC 2003 "Device Application" project.
(2) Add a new item to the project that is of the "Custom Control" type
template.
(3) Change the newly generated control class source to inherit from TextBox.
(4) Build the project.
(5) Open the main form.
(6) Drag an instance of new the control from the toolbox onto the form.
 
X

xtravar

Thanks, yes, I just tried it in a completely different class library
and it worked. I have found the problem: one of the controls in my
library was causing the designer to not render ANY controls.

And this 'trouble' control happens to be a subclass Form.

So now I guess the question is, what's so special about this Form that
it's messing up all the controls in the class library from rendering in
designer.
 
T

Tim Wilson

I'm not sure. I have seen "issues" with custom controls on visually
inherited forms in the designer where the same control operates as expected
on a basic form of type Form. So there may be something going on with how
custom forms are handled in the designer. However, I don't have a concrete
answer at this point as to the real cause of the issue.
 
X

xtravar

Okay, that was wacky as all hell.
I had a Form with an InputPanel reference. I already found out that I
needed DesktopCompatible(true) in order to get the Form to render in
the designer when I inherit from it.

What I did not foresee was that, by adding an InputPanel to the form,
it meant that I had to add DesktopCompatible(true) to ALL of the
controls in the library. They render fine when the Form is not present
in the library.

For the record, the controls in the library have no reference to
InputPanel nor the trouble-causing Form.

You'd think that marking the incompatible Form as DesktopCompatible
would override the status of the library as being incompatible.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top