Click to See Complete Forum and Search --> : Form Design Question


lskuff
February 22nd, 2006, 04:32 PM
I have a textbox on a main form that is in hexadecimal (4 nibbles)..... I am making another form that pops up when the user double clicks where they can change each bit...... For example... Let's say that the main form has:

txtHex: A5FF

the user double clicks and the next form comes up:

it has:
1010 0101 1111 1111

I was thinking that each binary digit be a check box....but I don't know what the best way to design this is. Do I need to make 16 unique text boxes? This seems like a pain to do... was wondering if anyone had any good ideas on how to go about this. Thanks -

darwen
February 22nd, 2006, 05:01 PM
A user control would be the way to go with this. I like the check-box idea, but with a user control you could set the number of bits and dynamically create them after setting a property to the number of bits required.

You could have a property for the number of bits and when you drag it onto a form you'd be able to set its value in the properties for the control e.g.


public class BinaryControl : UserControl
{
private int _bitCount = 8;
private int _value
private ArrayList _checkBoxes = new ArrayList();

public int BitCount
{
get
{
return _bitCount;
}

set
{
_bitCount = value;

CreateCheckBoxes();
}
}

public int Value
{
get
{
return _value;
}

set
{
_value = value;
UpdateCheckBoxes();
}
}
}


This way you could set the size of the control in the designer so that all the check boxes are contained inside of the bounding rect - the CreateCheckBoxes() method should position the check boxes next to one another which should be easy enough to code.

Darwen.

lskuff
February 22nd, 2006, 05:09 PM
awesome. Thanks so much. I knew there had to be an easy way to do something like this!

jmcilhinney
February 23rd, 2006, 03:47 AM
You might also want to look at the BitArray class, which might come in handy here.