Click here to Skip to main content
13,000,469 members (58,243 online)
Click here to Skip to main content
Add your own
alternative version


21 bookmarked
Posted 6 Apr 2006

Button Array Control

, 6 Apr 2006
Rate this:
Please Sign up or sign in to vote.
A dynamic button array control.


This will just be a small article, it won't explain how to create a user control since it's quite straightforward, it won't tell you how the control works because there is not much to it, it will tell you what it does and how you can use it in your own projects, since that's the real purpose of any control. Of course, if you have any doubts, downloading and looking through the code will help you get started. The user control source code and/or binary can be downloaded and used in anyway you like.


The control contains a dynamic button array; dynamic means you can create a matrix of buttons of any size, even at run time.

The control features a big button that can be placed on top or on the bottom, and if you don't want it, you can make it invisible. You can put one or several images on the buttons, you can specify the button's sizes or their separation, you can have them laid out in four different ways, left to right (L2R), right to left (R2L), top to bottom (T2B), or bottom to top (B2T). You can also set the text and the image alignment for all the buttons, among other design time properties.

Using the control

Using the control is very easy. First, you have import it to the toolbox. You can do this either by dragging the control's DLL or by browsing and adding the item. Once you get it on your toolbox, you just drag it and drop it on your project form and it's default 3x3 matrix layout will appear.

Then just edit the properties to fit your needs, just like any other control you've used before. The properties I implemented come with a short description, however, if you don't figure it out with that, you can look at the code to see how it all works, or you can write to me.

Pretty simple, right?

Some unbeaten issues

I did have some problems during the development, I thought I had finished the control quite well because some tests had passed fine, but then I tried new ones and a lot of problems came up. When developing a control, it is a little harder to test it all.

You must test at design time and run time too; anyway, the most challenging issues I worked out were the layout, the creation of the matrix, and the resizing at design time.

There are basically two issues I just couldn't work out, so if you read this and have some suggestions or any tips, they are more than welcomed. I wanted my control to have a nice icon, but it just wouldn't show. I added the icon I wanted to the project properties but when I added the control to the toolbox, it would always show the same default icon.

The other thing I couldn't get working was the button's texts. I wanted them to be modified at design time, so I created an ArrayList as a property so that it would show at design time, and it did, but it wouldn't let me modify them, just see them. So then I thought about using a collection editor just like the combobox.Item string collection editor, but no matter what I tried I got the same result, "read-only". I don't know if I have to make my own collection editor but it shouldn't be like that.

Last words

I hope the control helps you. I can think of many uses for it. So I hope yours is one of them. I'd appreciate to get a word from any one that uses it telling me how it's doing.

Any questions or comments are always more than welcomed.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Web Developer
Canada Canada
Althought i'm a Electronic Engineering, my stong side is IT.

I've developped code in different languages:
Assembly, C, Java, HTML, Javascript, Perl/CGI, VB6, and C#, in which i've been working latetly.

I'm also keen on Security and Cryptography topics, as well as on Multimedia Technologies.

You may also be interested in...


Comments and Discussions

Generalhum Pin
The Monz6-Apr-06 21:59
memberThe Monz6-Apr-06 21:59 
AnswerRe: hum Pin
Hotlinux7-Apr-06 5:21
memberHotlinux7-Apr-06 5:21 
GeneralRe: hum Pin
Pascal Ganaye212-Apr-06 22:08
memberPascal Ganaye212-Apr-06 22:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170624.1 | Last Updated 6 Apr 2006
Article Copyright 2006 by Thoughthopper
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid