On May 21, 12:12 pm, "zhaod...@gmail.com" <zhaod...@gmail.comwrote:
I derived a panel class:
public class DeskPanel : System.Windows.Forms.Panel
Now I want to use the visual designer to add controls in MyPanel
class. But I noticed that the visual designer didn't work.
I try some other ways, and found the if i derived my panel from
UserControl class it works. However, I thought deriving from Panel is
more rational. I have several panels (such as calendar panel, contacts
panel, photo viewer... and I will switch them in my main form base on
the user choice)
If you mean that you are trying to add controls to your pane at design
time when your panel hasn't been dropped onto a Form (or other
control) then you can't (to my knowledge). What you need to do is to
create a user control (not a panel) then add your controls onto that
at design time (as you have discovered).
What is is about Panel that you think is more logical than
UserControl? You can have several of them, and switch between them
exactly as you can a panel - in fact the main difference between a
Usercontrol and a panel would seem to be that you can do what you
require with a UserControl and you can't with a Panel!
Of course, if you REALLY want to use Panel, then you need to put that
panel onto something to be able to design it, so you could put it on
your form, add controls to it, make it invisible, add our other
panels, do the same etc.