Okay, here is the final code as I see it......
Tim - In the 20 or so years I've been doing this, if
there is one thing I've learned, it is that there is
no such thng as '
the final code'
So moving along, there are other problems that you
don't see yet. The first is that your UserControl class
uses a non-static command method.
When a command method is non-static, the AutoCAD
managed runtime creates a new instance of the class
that declares the method, for each document that the
coimmand is invoked in, and caches them.
When you invoke the commad a second time in the
same document, the cached instance of the class that's
associated with that document is the instance which
the method is invoked on.
Your "MyUcPalette" command method is a non-static
member of UserControl1. That means that to invoke
that method, there must be an instance of UserControl1
that already exists, which is the instance that AutoCAD
creates when you issue the command in a document the
first time.
Your command method is then creating another instance
of UserControl1, when the command is invoked. But the
problem (which is not easily seen), is that subsequent
invocations of the command, causes the non-static
command method to be invoked not on the instance of
UserControl1 that your command creates, but rather on
the cached instance AutoCAD createed for you, the first
time you issue the command in each document.
In otherwords, if you have 3 documents open, and you
issue the MyUcPalette command in each, there will be
3 instances of UserControl1 created, one for each open
document the command was issued in. Your code as it
is written doesn't even know about them.