473,652 Members | 3,173 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4774
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 InitializeCompo nent, was
added to the InitializeCompo nent 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
1283
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 Inherited Control. Is there anyway to do this? For example, I have an ADD button which is inherited and a EXIT button which is inherited. The reason I made them inherited is because I want to use the function of these buttons in other forms and don't...
1
4019
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 same way a menu does. To do this my control needs to get notified when the user tried to click off of it. The Leave and LostFocus events of the UserControl work most of the time but not always. For example, if they click on a part of the form...
0
1904
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 several user controls that are inherited user controls, based on one class, which is in turn based on System.Windows.Forms.UserControl. We'll call this class "UserControlBase". My first problem is that UserControlBase implements some public...
4
6065
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 of a Custom User Control, generated by adding a new Custom User Control to a project with VS.NET.
0
971
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 Form, I don't know why the Inherited Web User Control have not any properties inherited from Base Web User Control. How should I do? The based web user control as: using System; ....
2
1833
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 inherited user control ...", then I browser to c:\winnt\microsoft.net\framework\v1.1.4322\system.windows.forms.dll
7
3161
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 inital use of the UserControl component works. However, if the Helper Project is recompiled, the UserControl does not work
0
1309
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 keyboard. What I have done is that every keystroke is entered into a textbox within my User Control. Want I want to do is to take that user input from keyboard textbox and display it within my main form. I also want to be able to close this control and...
3
1485
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 the same spot as each other, depending on what is being called at that particular time by the user. I have been trying to use Inherited user controls, but I am not able, and/or don't know how to retrieve the data from my Inherited user control. If...
0
8367
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8703
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8589
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7302
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6160
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4145
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4291
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1914
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1591
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.