What is the best way to hide and re-arrange GUI elements (field boxes, buttons, labels.. etc) in Visual Studio Compact Framework 3.5 C#?
I have tried to implement hiding of fields and labels, and at the moment it seems like a very cumbersome process (I am not sure if it can be improved). Example of how I do it is in code below...
As you can see it can get pretty messy. What I am doing there is first generate a boolean control array, and using that array I first hide specified fields and then move everything up to remove empty spaces. I am trying to find a better way to do this.
I also looking for someways to possibly have control on arrangement of those GUI elements. Let's say I want to have LastName filed come up first, not FirstName field. How could I do it without having to rewrite the code in this form?
// Generate boolean array to control visible status of each field
bool[] hideControl = new bool[13];
for (int i = 0; i <= 12; i++)
{
hideControl[i] = Convert.ToBoolean(MobileConfiguration.Settings[i]);
}
// Difference in pixels between two input panels
int diff = this.txtLastName.Location.Y - this.txtFirstName.Location.Y;
// Hide Fields
hideFields(hideControl);
// Movie Fields
moveFields(hideControl, diff);
..................
// hideFields function
if (hideValue[0] == true)
{
// Hide Install
this.txtFirstName.Visible = false;
this.lblFirstName.Visible = false;
}
// And so forth for each 12 fields
...................
// moveFields function
if (hideValue[0] == true)
{
// LastName -- 2nd field
this.txtLastName.Location = new Point(this.txtLastName.Location.X, (this.txtLastName.Location.Y - diff));
this.lblLastName.Location = new Point(this.lblLastName.Location.X, (this.lblLastName.Location.Y - diff));
// So forth for 11 fields
}
if (hideValue[1] == true)
{
// Move up other 10 fields
}
if (hideValue[2] == true)
{
// Move up other 9 fields
}
My gui for that form looks as follow (label and textbox on a single line):
PanelName1
FirstName ______
LastName _______
Addresss _______
....etc