Solved

create a class derived from a Panel

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Problem with SqlConnection 4 160
Is setting this variable making a duplicate in memory 4 31
Error on Add method 1 38
What namespace do I need to import? 2 14
Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

861 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

24 Experts available now in Live!

Get 1:1 Help Now