Click here to Skip to main content
Click here to Skip to main content

Multiple Base Number Editor

By , 22 Mar 2010
 

Introduction

My initial motivation to write this component came after I was writing a component to support decimal and hexadecimal editing number at work. When I searched for some control or code on the internet, I realized that there was almost nothing like what I was looking for. Probably few people really need to enter numbers in base such as binary, octal or hexadecimal, but here we go.

Initially, my intent was to show the work and the code that I developed, but besides the code is not really long describing it in an article seems boring and unnecessary extensive. So this article is just to show the controls features and if the reader desires, he can download the source code or the assembly.

Background

This code was written using Visual Studio 2008 Express Edition and requires .NET Framework 3.5. Assembly verification was done using Microsoft's FxCop. Code Documentation files were generated using Doxygen.

Using the Code

The MultipleBaseNumberEditor is a Windows Forms component that extends a System.Windows.Forms.UserControl and defines an editor that allows editing a number in any of these bases: binary, octal, decimal or hexadecimal. To use MultipleBaseNumberEditor in your project, you can either add the source code MultiBaseNumberEditor.cs to your solution or add the numbersEditors assembly reference. Adding the source code to the project requires that the project be compiled once before it appears on Visual Studio's Toolbox (under your projects tab).

It is also possible to register the assembly in GAC. For that, follow the instructions found in this link: http://msdn.microsoft.com/en-us/library/ex0ss12c(VS.80).aspx

If the assembly is not registered, the control will not appear in .NET Framework Components when trying to add it to the toolbox. To add it to the toolbox manually without registering in GAC, click on browse and select the numbersEditors.dll.

To add the MultipleBaseNumberEditor component manually through Choose Toolbox Items, right click on Toolbox area and select "Choose Items", then click on "Browse...", find the numbersEditors.dll and click on Open. The component will appear in the list as shown in Figure 1. Make sure the component is checked, then click ok, the component shall appear on Toolbox.

addreference.jpg

Figure 1: Adding MultipleBaseNumberEditor component to Project

Drop the MultipleBaseNumberEditor from the Toolbox into a form on designer, see Figure 2. Check out the MultipleBaseNumberEditor properties on Properties view (Figure 3).
Besides most common properties from a Control, I list below the properties specifically from MultiBaseNumberEditor:

  • Base
  • Value
  • Minimum
  • Maximum
  • DisplayBaseChooserButton
  • BaseChooserStyle
  • ConfigBinary
  • ConfigOctal
  • ConfigDecimal
  • ConfigHexadecimal
  • DisplayAllBaseConversions

Form1.jpg

Figure 2: Dropping the MultipleBaseNumberEditor on the Form

properties.jpg

Figure 3: Check out the properties on Properties view

Base is of type BaseNumber. The current defined bases are defined as:

  public enum BaseNumber {
    Binary,
    Octet,
    Decimal,
    Hexadecimal
  };         

Value is an unsigned long. The control does not support negative values.

Minimum and Maximum define the limits Value can be.

Use the DisplayBaseChooserButton to show or hide the base chooser button. With the chooser button, the control allows the user to click and select which base he wants that number to be displayed.

The BaseChooserStyle defines the chooser button style. It can be a simple button or a drop-down list.

  public enum BaseChooserStyle {
    Button,
    Combo
  } 

The ConfigBinary, ConfigOctal, ConfigDecimal and ConfigHexadecimal are settings specifically to each base number allowing the user sets if control should display prefix, suffix and if it should padleft with '0' character.

The MultipleBaseNumberEditor provides a default tooltip that within prints the current value in all available formats. To turn that tooltip on or off, set the DisplayAllBaseConversions.

The control provides the events, besides those inherited from UserControl:

  public event EventHandler ValueChanged; 	// Occurs when Value changes
  public event EventHandler BaseChanged; 	// Occurs when the base number changes

In Figure 4, it shows the MultipleBaseNumberEditor into a form with different settings.

sample.jpg

Figure 4: A sample view

Also, this assembly is CLS Compliance (for more information about CLS Compliance: http://msdn.microsoft.com/en-us/library/bhc3fa7f.aspx).

Future Work

  • This control extends a UserControl. It could extend a TextBox. One of the challenges of extending from TextBox is how to draw or add the other controls added here to select the base (that can be a button or combo).
  • A similar control to work with large byte arrays, displaying groups in any of the chosen bases.
  • Possibility to extend this control to any base number editor (I wonder what would be the purpose). Possibility to add more features.
  • Provides more flexibility allowing what base the control will display and the user can select.

History

  • 22nd March, 2010: Initial post

License

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

About the Author

Ramon.Pinho
Software Developer
Brazil Brazil
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralInvalid sample.zipmemberDoncp24 Mar '10 - 12:29 
GeneralParabénsmemberIvo Closs22 Mar '10 - 16:21 
GeneralRe: ParabénsmemberRamon.Pinho23 Mar '10 - 14:19 
GeneralCalc.exememberaspdotnetdev22 Mar '10 - 10:59 
GeneralRe: Calc.exememberRamon.Pinho22 Mar '10 - 13:35 
GeneralSomething similarmemberPaw Jershauge22 Mar '10 - 10:32 
GeneralRe: Something similarmemberRamon.Pinho22 Mar '10 - 14:37 
GeneralRe: Something similarmemberPaw Jershauge23 Mar '10 - 0:22 
GeneralInvalid sample.zipmemberDoncp22 Mar '10 - 8:17 
AnswerRe: Invalid sample.zip [modified]memberRamon.Pinho22 Mar '10 - 14:08 
GeneralRe: Invalid sample.zipmemberDoncp23 Mar '10 - 6:17 

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

Permalink | Advertise | Privacy | Mobile
Web01 | 2.6.130516.1 | Last Updated 22 Mar 2010
Article Copyright 2010 by Ramon.Pinho
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid