Solved

create a class derived from a Panel

Posted on 2003-11-17
5
258 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
  • 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now