Solved

create a class derived from a Panel

Posted on 2003-11-17
5
267 Views
Last Modified: 2010-04-16
Experts,

I am trying to create a class, MyPanel, which is derived from System.Windows.Forms.Panel.

Then I wanted to add a couple of standard controls to MyPanel. I couldn't find a way to specify their properties by using design view. All I have to do is to write code to define properties like Location and Size. As I am doing it, I have no any clue how does it look like and if it fits with other controls. then I have to run the program to actually see the appearance of the panel and its containing controls.

If I create a class derived from System.Windows.Forms.UserControl, it seems solve the problem. I can design the controls in a visual view. But it makes the code bigger. I wonder if it effects the performance and code efficiency.

Any better ideas or suggestions?
Thanks
0
Comment
Question by:stone123
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 10

Accepted Solution

by:
smegghead earned 150 total points
ID: 9767099
I have come across exactly this problem, it's a shame that the designed doesn't cope with inherited controls.

The way I got around this was to have a separate project which contains the definition of my panels, just created normally on a form, then I just cut and paste the 'windows form designer generated code' section to my inherited panel. This works fine, although it's a bit fiddly.

Hope this helps a bit.

Smg.
0
 
LVL 1

Expert Comment

by:AJMartin
ID: 9769806
One alternative is use an automatic layout manager class, that way, you don't really need to have a design time view. :)

Or, you could check out this article on MSDN:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconenhancingdesign-timesupport.asp

Here's a quote:
"For example, if you define a property of a custom type on a control, you can provide a custom user interface, or type editor, to edit the value of that property using a property browser. You can build a class called a designer that can manage a variety of aspects of a component or control's appearance and behavior at design time."

I hope that helps!
0
 
LVL 1

Author Comment

by:stone123
ID: 9772269
Thanks, Smg and AJMartin. Your suggestions help.
I am using a System.Windows.Forms.UserControl, it works just fine. I wonder if there is any potential problems in the future in my case of implementation.
Can any one have a little comment on the UserControl object? What is your experience of using it?
0
 
LVL 10

Expert Comment

by:smegghead
ID: 9772322
It's very good for what it's designed for, and if it solves your problem, then I can't see there being any problem with it. It's probably going to be a bit bulkier than directly coding your classes individually, but if it makes it easier to use / maintain, then go for it.

Smg.
0
 
LVL 1

Author Comment

by:stone123
ID: 9780827
ok, looks like no more inputs from your guys. then I go ahead to close the thread and give out the points.
Smg, what you advised is quite a good work-around. Thanks a lot.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question