在 Visual Studio Compact Framework 3.5 C# 中隐藏和重新排列 GUI 元素(字段框、按钮、标签等)的最佳方法是什么?
我曾尝试实现字段和标签的隐藏,目前这似乎是一个非常繁琐的过程(我不确定是否可以改进)。我如何做到这一点的示例在下面的代码中......
如您所见,它可能会变得非常混乱。我在那里做的是首先生成一个布尔控件数组,并使用该数组我首先隐藏指定的字段,然后将所有内容向上移动以删除空格。我正在努力寻找更好的方法来做到这一点。
我还在寻找可能控制这些 GUI 元素排列的方法。假设我想让 LastName 文件首先出现,而不是 FirstName 字段。我怎么能不重写这种形式的代码呢?
// 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
}
我对该表单的 gui 如下所示(标签和文本框在一行):
PanelName1
FirstName ______
LastName _______
Addresss _______
....etc