|
Hello there, I've created a custom control which inherits from the Panel control and contains a bunch of other controls inside of it. The problem is that cannot use the design view to design the control the way I want (placement of inner controls, sizing, etc.). I do not understand why I can't see the controls that I add to it the same way I see controls added onto a form. Instead, I see a sequential layout which doesn't allow me to do much with the mouse, like re-adjust the borders, drag controls to a desired area, etc. As a workaround, I'm forced to have my class written in the following manner: public partial class MyPanel : Panel /*UserControl*/ When I want to design the control, I switch it to: public partial class MyPanel : UserControl /*Panel*/ Although this seems to do the trick, it's not the most elegant solution. I realize that I could inherit from the UserControl class and simply add a Panel control inside my user control but that would complicate things elsewhere in my code. Is there a way to enable the design view when creating inherited controls (i.e. through the use of custom designers maybe) or is this simply not supported in Visual Studio? Thanks! | | j_nicola Wednesday, September 09, 2009 8:23 PM | UserControl and Panel are very similar. Why would you want to Inherit from Panel instead of UserControl? You don't need to add a Panel to the UserControl you can use the UserControl instead of a Panel. You can always hijack the usercontrol designer if it's really necessary, but I expect that it isn't needed in this case. For an example of hijacking the usercontrols designer see the following thread: http://social.msdn.microsoft.com/Forums/en-US/winformsdesigner/thread/55a561bd-b22a-486d-b8d8-59f6612bb317
Mick Doherty
http://dotnetrix.co.uk- Marked As Answer byKira QianMSFT, ModeratorWednesday, September 16, 2009 8:46 AM
-
| | Mick Doherty Sunday, September 13, 2009 11:18 AM | Hi j_nicola, >I've created a custom control which inherits from the Panel control and contains a bunch of other controls inside of it. If you want to make a custom control with a lot of other controls, I recommend you to create a user control instead of inheriting from Panel. User control is the one design for that purpose. It just like a panel on which you can put any visible controls onto it. Inheriting from a Panel or other control is just a way let you enhance the function or change the look in code. It isn't suitable to add other controls onto its surface. Do you have any special reason to inherite from Panel? Sincerely, Kira Qian Please mark the replies as answers if they help and unmark if they don't.- Marked As Answer byKira QianMSFT, ModeratorWednesday, September 16, 2009 8:46 AM
-
| | Kira Qian Friday, September 11, 2009 6:31 AM | Hi j_nicola, >I've created a custom control which inherits from the Panel control and contains a bunch of other controls inside of it. If you want to make a custom control with a lot of other controls, I recommend you to create a user control instead of inheriting from Panel. User control is the one design for that purpose. It just like a panel on which you can put any visible controls onto it. Inheriting from a Panel or other control is just a way let you enhance the function or change the look in code. It isn't suitable to add other controls onto its surface. Do you have any special reason to inherite from Panel? Sincerely, Kira Qian Please mark the replies as answers if they help and unmark if they don't.- Marked As Answer byKira QianMSFT, ModeratorWednesday, September 16, 2009 8:46 AM
-
| | Kira Qian Friday, September 11, 2009 6:31 AM | UserControl and Panel are very similar. Why would you want to Inherit from Panel instead of UserControl? You don't need to add a Panel to the UserControl you can use the UserControl instead of a Panel. You can always hijack the usercontrol designer if it's really necessary, but I expect that it isn't needed in this case. For an example of hijacking the usercontrols designer see the following thread: http://social.msdn.microsoft.com/Forums/en-US/winformsdesigner/thread/55a561bd-b22a-486d-b8d8-59f6612bb317
Mick Doherty
http://dotnetrix.co.uk- Marked As Answer byKira QianMSFT, ModeratorWednesday, September 16, 2009 8:46 AM
-
| | Mick Doherty Sunday, September 13, 2009 11:18 AM | Thank you !! I hijacked the usercontrol designer as it was described in the thread you posted and it worked perfectly! I realize that I "should" inhereit from the UserControl class instead however in my case, it would cause more damage then good at this point in my project. Besides, the fundamental purpose of object-oriented design is that you should be able to inherit from any class you desire. As such, ifyou createa contol that's inherited from another control, the same principle should imply, regardles if its inheriting a usercontrol or not...I find that this is a limitation that shouldnot exist in the first place. | | j_nicola Wednesday, September 16, 2009 4:17 PM |
|