473,396 Members | 1,765 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

User Control v Inherited form

Hi,

I'm a C++ developer coming fresh to c# for GUI development. For the project
I'm working on, I need a specialised control (a treeview derivative) which
would be very useful in other applications I might need to write.

Back in my day ;-) I would have written a user control for use from within
VB, which I could still do, however - I also have the (more appealing from
my perspective) option of deriving a control from the .NET base control.

What is the popular wisdom on these two alternatives?

thanks,

AD

Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Nov 17 '05 #1
2 4765
Hi,

I use the user control in order to merge several controls and to handle the
UI threads within the same environment. Now, If I need to upgrade the
functionality of a base control I will create a component that inherits from
that base class.

One tip, in order to your control appear on the toolbox first add a
usercontrol and then change the inheritence your treeview. Also C# is giving
you the opportunity to design your own from scratch inheriting from component.

hope this helps
Salva
"adbarnet" wrote:
Hi,

I'm a C++ developer coming fresh to c# for GUI development. For the project
I'm working on, I need a specialised control (a treeview derivative) which
would be very useful in other applications I might need to write.

Back in my day ;-) I would have written a user control for use from within
VB, which I could still do, however - I also have the (more appealing from
my perspective) option of deriving a control from the .NET base control.

What is the popular wisdom on these two alternatives?

thanks,

AD

Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com

Nov 17 '05 #2
Hi adbarnet,

"adbarnet" wrote:
Hi,

I'm a C++ developer coming fresh to c# for GUI development. For the project
I'm working on, I need a specialised control (a treeview derivative) which
would be very useful in other applications I might need to write.

Back in my day ;-) I would have written a user control for use from within
VB, which I could still do, however - I also have the (more appealing from
my perspective) option of deriving a control from the .NET base control.

What is the popular wisdom on these two alternatives?

thanks,
AD


I have created several specialised controls by deriving from UserControl, it
adds an extra level of indirection as the specialised control(s) would be
embedded in the UserControl instance. This has the benefit that it shields
the user from how you made the control (although not entirely perhaps), and
prevents abuse of the control (invalid entries etc). If you would like to
still expose the underlying control(s) (in your case a treeview), you could
expose a property that does this.

Any properties you make in the UserControl derived class are also displayed
in the properties tab for an instance of the control on a form.

You can add the user control to the form designer toolbox (contextmenu/add
controls); or if the control is in the same project I think it is added to
the User Control tab in the toolbox. If the IDE doesn't do it automatically
then you can still add it yourself, drag the control on the form and set some
properties.

I once derived from DataGrid to make my specialised control, but I noticed
that all initialization code from the control in InitializeComponent, was
added to the InitializeComponent method for the form that contained the
control. I didn't really like that because that was a lot of code (you would
know if you use DataGrid). I still don't know the reason for this. I could
have put the initialization somewhere else but that didn't seem a like good
idea. I ended up making a UserControl for my specialized control, but more or
less for another reason. My control was actually a logging table with no
other real functionality, so there was no need to directly expose the
underlying DataGrid.

So IMHO your choice should depend on the nature of the control you're
making. If it enriches or extends functionality you should derive from the
control directly. If it restricts functionality to a specific user-interface
then you should make it a UserControl.

Hope this helps,
Tom T.
Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Terrance | last post by:
Hello all I have a question I'm hoping someone can shed some light on. I have 2 user Inherited Controls on a form. When I click 1 inherited control I would like to change the text of the other...
1
by: Rhy Mednick | last post by:
I'm creating a custom control (inherited from UserControl) that is displayed by other controls on the form. I would like for the control to disappear when the user clicks outside my control the...
0
by: Jim | last post by:
I am having some trouble with user controls and would appreciate any input / advice on where to go with this... :) 1. The first problem, and perhaps the root of the others, is that I have...
4
by: Paradox | last post by:
Hey, I'm trying to figure out what situations call for the use of a derived form control such as: public class myListBox : System.Windows.Forms.ListBox and what situations call for the use...
0
by: ABC | last post by:
I write a Base Web User Control which contains several public properties and a Inherited Web User Control which only have some codes in new method. When I use the Inherited Web User Control on Web...
2
by: Ryan Liu | last post by:
Hi, Can someone give me a hlep on inherited user control? I try to inherite windows forms user control, like ListView. From Visual studio 2003, I right click a folder and selct "Add...
7
by: crowl | last post by:
VS.2003, .NET Framework 1.1, C# My goal: Creating a dll (helper.dll) which contains some UserControls and some other helpful classes in order to use it in other projects. Symtoms: The...
0
by: MikeY | last post by:
Hi everyone, I posted a question very early today, but maybe I wasn't articulate enough. Hopefully this will illicit a response I've created a windows form and a User Control. This is a...
3
by: MikeY | last post by:
Hi everyone, I'm trying to figure out, on my windows form, of what is the best way to add various custom controls at various times during run-time. The problem is that they will need to be in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.