简体   繁体   中英

Best way to hide and rearrange GUI elements in Visual Studio Compact Framework 3.5 C#?

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

Put your controls onto a panel, and then you can hide the panel which would hide the controls that it is the parent of, bear in mind this could affect looping over controls but this can be easily remedied. Moving the panel will also move the controls.

The question really is whether or not you could reuse controls though or whether you have too many controls on your form to make it easy for a user to understand.

If you still need to loop over controls you could use this extension method

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM