473,769 Members | 2,019 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Inheriting from UserControl...

I'm trying to create a C# composite control and have inherited
from UserControl. This new control contains 9 buttons with images on
them ( no text ).

Firstly, what is the best way to expose these 9 buttons to the
developers who will be using my control. I want them to be able to
change visibility, enablement, onClick etc for each button, but not be
able add any new buttons. I initially thought of exposing them as some
kind of fixed array, but wanted the opinions of those with more
experience. In the case of an array or collection, what is the correct
way of exposing this so it can be customised via the object inspector.

Secondly, if I want a specific icon/bmp to appear in the ToolBox for my
component, where must this icon/bmp be stored. I know I need to use
ToolboxBitmap(t ypeof(MyCompone nt), "MyComponentBit map") attribute, but
can this exist in an image list or should it be placed somewhere else?
Dec 4 '05 #1
9 1927
"Dominique" <Do*******@disc ussions.microso ft.com> wrote in message
news:47******** *************** ***********@mic rosoft.com...
I'm trying to create a C# composite control and have inherited
from UserControl. This new control contains 9 buttons with images on
them ( no text ).

Firstly, what is the best way to expose these 9 buttons to the
developers who will be using my control. I want them to be able to
change visibility, enablement, onClick etc for each button, but not be
able add any new buttons. I initially thought of exposing them as some
kind of fixed array, but wanted the opinions of those with more
experience. In the case of an array or collection, what is the correct
way of exposing this so it can be customised via the object inspector.
Pass them out as a collection the same way the toolbar does it with the
toolbar buttons.
Secondly, if I want a specific icon/bmp to appear in the ToolBox for my
component, where must this icon/bmp be stored. I know I need to use
ToolboxBitmap(t ypeof(MyCompone nt), "MyComponentBit map") attribute, but
can this exist in an image list or should it be placed somewhere else?


As a resource I would say, although I haven't done it. Just add the bitmap
to your project and specify it's build action as resource.

Michael
Dec 5 '05 #2
"Michael C" wrote:
Pass them out as a collection the same way the toolbar does it with the
toolbar buttons.


OK, but what is the proper syntax for exposing this collection? I think I
will use an inherited ArrayList for simplicity.

Dec 5 '05 #3
Hi,
OK, but what is the proper syntax for exposing this
collection? I think I will use an inherited ArrayList for >

simplicity.

You should use a HashTable, it will give you much better performance.

Happy Coding,

Stefan
C# GURU
www.DotNETovation.com

*** Sent via Developersdex http://www.developersdex.com ***
Dec 5 '05 #4
OK thanks for that. I now have my collection appearing in the Property
inspector, but I cannot set each button's event from there. Is there
something else I need to do for this to be enabled?

Dominique.

"Stefan" wrote:
Hi,
OK, but what is the proper syntax for exposing this
collection? I think I will use an inherited ArrayList for >

simplicity.

You should use a HashTable, it will give you much better performance.

Happy Coding,

Stefan
C# GURU
www.DotNETovation.com

*** Sent via Developersdex http://www.developersdex.com ***

Dec 5 '05 #5
"Dominique" <Do*******@disc ussions.microso ft.com> wrote in message
news:CA******** *************** ***********@mic rosoft.com...
OK thanks for that. I now have my collection appearing in the Property
inspector, but I cannot set each button's event from there. Is there
something else I need to do for this to be enabled?


Have one event which passing in the button as an enum parameter.

Michael
Dec 5 '05 #6
"Stefan" <we******@dotne tovation.com> wrote in message
news:Ob******** ********@TK2MSF TNGP14.phx.gbl. ..
Hi,
OK, but what is the proper syntax for exposing this
collection? I think I will use an inherited ArrayList for >

simplicity.

You should use a HashTable, it will give you much better performance.


I'd just define my own collection in a case like this that does not need
performance. That way you can have the exact functionality you need.

Michael
Dec 5 '05 #7
I would take a completely different tack on this than the other
responders.

First, are sure that there will only ever by 9 buttons? Do they
indicate something specific? I can, for example, having them in a
three-by-three square, something like the text alignment buttons in
Visual Studio Designer. You know: "upper left", "middle left", "lower
left", "upper middle"... that sort of thing.

If that's the case, then I submit that you don't want to just expose
them in a collection. Sure, that's the easy way to do it, but what you
really want is to create a UserControl that returns an indication of
what position the user chose. If you expose the nine buttons in a
collection then you're showing your client classes _how_ you solved the
problem: you're exposing implementation.

If we're taking the position buttons user control as an example, then
what you really _want_ to do is expose an interface that says, "This
control allows the user to choose one of nine positions, but I'm not
telling you how it does that." So, I would make it expose events /
properties like this:

1. A "position" enumeration: TopLeft, MiddleLeft, BottomLeft, etc. It
should have a [Flags] attribute so that the positions can be combined.
2. A "position chosen" event (just one event) that carries in its event
arguments which position the user chose.
3. A method to set which positions the user is allowed to choose (via a
combination of the "position" enumeration).
4. A method to set which positions the user is allowed to see (via a
combination of the "position" enumeration).
5. Nine properties for each button property that you want to expose to
clients, for example, "TopLeftIma ge," "MiddleLeftImag e", etc.

Yes, this is a whole lot more work, but the advantage is that your
callers don't know how the control does its job. You could change it
from buttons to a radio button list and the same interface would still
apply.

There are exceptions (the ToolBox being one), but as a general rule
it's bad form to allow clients to see inside your UserControl and get
directly at controls therein, because then that locks you into one
implementation, and doesn't allow for multiple UserControls that do the
same thing (implement the same interface) but do it in different ways
(look & feel).

If you do decide to go the easy way and just expose an ArrayList of
buttons or something, make sure that you take care not to give your
clients direct access to your inside structures so that they can
cheerfully add and remove buttons from your control without your
consent. If you want them to never be able to change how many buttons
there are (just their attributes), build the collection / array to
return every time your client asks for the button list. Clients will
still have access to the original buttons, but not your internal
collection structure.

Dec 5 '05 #8
>> Bruce Wood << >> Wrote <<
I would take a completely different tack on this than >> the other

responders.

I agree with Bruce if you have the time make it scalable as Bruce
explained.

To add to Bruce's thought you take it one step further and create your
own 'Button' Class inheriting from 'Button', here is a quick example I
created just to give you an idea of were to start:

namespace Sle.Control
{
[System.Componen tModel.DefaultP roperty("Text") ,
System.Web.UI.T oolboxData("<{0 }:WebCustomCont rol1
runat=server></{0}:WebCustomCo ntrol1>")]
public class WebCustomContro l1: System.Web.UI.W ebControls.WebC ontrol
{
private string text;

[System.Componen tModel.Bindable (true),
System.Componen tModel.Category ("Appearance "),
System.Componen tModel.DefaultV alue("")]
public string Text
{
get
{
return text;
}

set
{
text = value;
}
}

protected override void Render(System.W eb.UI.HtmlTextW riter output)
{
output.Write(Te xt);
}
}
}
Happy Coding,

Stefan
C# GURU
www.DotNETovation.com

"You always have to look beyond the horizon and can never be complacent
-- God forbid we become complacent."

Jozef Straus

*** Sent via Developersdex http://www.developersdex.com ***
Dec 5 '05 #9
"Bruce Wood" <br*******@cana da.com> wrote in message
news:11******** *************@z 14g2000cwz.goog legroups.com...
I would take a completely different tack on this than the other
responders.


You've misinterpreted my response. I wasn't suggesting to expose a
collection of actual command buttons. Instead I would create a simple class
with the properties desired and expose a collection of those. This still
hides the implementation underneath but avoids the situation of having
several related functions, eg ButtonPressed(i ndex), ButtonColor(ind ex) etc.

Michael
Dec 6 '05 #10

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

Similar topics

2
1410
by: Kevin Blackwell | last post by:
This is probably a basic c# question, but I'm having problems with it. I currently have a project that contains two classes. From the calss view. Class1 Class2 I have included a usercontrol in class 2. I dropped the control into a form in class one. What I'm looking to do is fill a control's text box with information from Class1.
4
1418
by: Joel Barsotti | last post by:
On certain pages I want to have a user control that is derived not directly from the usercontrol class, but from a class that extends the UserControl class so my objects will have a some guaranteed functionality. But my problem is that when I do this, the ascx file won't go into design view. Other than switching the inheritance of my ascx.cs files back and forth I don't know a way to get around this.
4
1381
by: Alan Silver | last post by:
Hello, I am displaying product details on a page and am allowing the site owner to specify the style in which the product details are displayed. I am debating which of two approaches to use here and would appreciate some comments. I intend to write a control that handles the actual display. This control would have a method that gets passed the product ID and the display style ID. It would pull the product details from a database and...
2
1486
by: Charles Law | last post by:
I have a base class - ComponentBase - that inherits from UserControl. My class implements IComponentBase, which defines a minimal set of core properties and methods. All my other components inherit from ComponentBase. I have defined IComponentBase in a common assembly so that my other projects reference this rather than the (large) library that contains the component implementation.
4
1199
by: elziko | last post by:
I would like to do the following: Create a class that inherits from a usercontrol. Then add a control to the designer Call this new class ClassA. Many controls I need will start off like this so I'd like to create all controls form now on from this base control. So, for example, I inherit from this base control and add the further controls required to form this part of my UI. Call this ClassB
3
1527
by: YYZ | last post by:
I swear I've done my research, and now I was just hoping someone could explain this to me. I've got a base class (usercontrol) that I am using just as an interface. Meaning, I've defined several MustOverride subs in there, and also a public property. I'm going to inherit a bunch of usercontrols from this one superclass (terminology correct?) and then they all have to make sure they can respond to that set of functions that I've...
4
6738
by: DanG | last post by:
Howdy, On past .NET projects, I only had System.Web.UI.Page forms. One application needed a set of functions to do processing against the Page, Session and Request objects associated with the current Form. I handled this by making a new class (BasePage) which inherits from System.Web.UI.Page. Each form would then inherit from BasePage rather than System.Web.UI.Page. I am now on a project that has both System.Web.UI.Page and
1
1742
by: =?Utf-8?B?a2Fu?= | last post by:
hi, Consider i have built a UserControl say 'ColorMixer' in proj 'Step1'(Windows Control Proj). Now when create another proj 'Step2' as Windows Control and try adding 'ColorMixer' as inherited ctrl to create new 'ColorMixerX' ,following problem arises. Above process completes successfully,but when i try to bring up the Designer for newly created 'ColorMixerX' the Designer show following err msg : "An error occured while loading the...
2
1295
by: Charlie Brown | last post by:
I have two classes, one that inherits from UserControl called Base. I have a second class that inherits from Base. I do not want to expose a lot of the properties of usercontrol beyond the Base control. For example, lets say I want every control that inherits from Base to have a RED background and not be able to change it. Currently, backgroundcolor is available in the designer as a color choice. Can I change the scope of something to...
0
10035
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...
1
9984
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8863
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...
0
6662
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5293
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
5441
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3949
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3556
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2811
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.