Buggy-Looking Behavior

P

Peter

I hate to jump to the conclusion that there is a bug going on here, so maybe
someone can help me.

I have added a new Class Library project to my solution, and to that I have
added a new User Control. I have placed a couple of things on its design
surface, and then, after adding references to this project into my main one,
dragged an instance of that control onto my main form in the form designer.

When I do that, one of several completely out-of-control things happens:
1) Sometimes, it won't give me an instance at all. Instead, I get a message
that says "Object reference is not set to an instance of an object."
2) Sometimes, it drags on ok, but the next time the form window refreshes,
all controls on the form have disappeared except for the custom one. Upon
inspecting the Windows Form Designer generated code, this is sometimes
because all the other controls have disappeared from the call to
Me.Controls.AddRange --- but sometimes they are still there; they just don't
show up until I remove the custom control from Me.Controls.AddRange.
3) Sometimes the entire form breaks and I get a white screen that says the
document cannot be designed or some other gobbledygook. Then I have to
manually remove the custom control from the guts of the Form Designer code
for it to work again.

This seems to happen to every custom control I design, and I can't figure
out why. It's rather hard on the ol' productivity.
 
P

Phill W.

Peter said:
I have added a new Class Library project to my solution, and to that I
have added a new User Control. I have placed a couple of things on its
design surface, and then, after adding references to this project into
my main one, dragged an instance of that control onto my main form in
the form designer.
1) Sometimes, it won't give me an instance at all. Instead, I get a
message that says "Object reference is not set to an instance of an
object."

That sounds like you have code in the UserControl that is running at
/Design-Time/ and falling about in a heap. The DesignMode property on
the Control class allows you to detect this.
2) Sometimes, it drags on ok, but the next time the form window
refreshes, all controls on the form have disappeared except for the
custom one.

Quite likely, this is a by-product of the first problem. The Designer
(/really/) doesn't like having Exceptions thrown at it and is probably
getting quite upset by this.
This seems to happen to every custom control I design, and I can't
figure out why. It's rather hard on the ol' productivity.

Is there any reason you're adding a class library then putting a
UserControl /into/ it, rather than just creating a new UserControl
directly?

Regards,
Phill W.
 

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