如何再次显示表单后如何刷新?

时间:2012-12-05 22:05:42

标签: c# winforms

我正在使用C#Windows窗体应用程序创建一个程序。

让我告诉你我正在做的事情:

  1. 登录程序(登录系统)
  2. 该程序将确定用户的权限值(让我们说我是#3;)
  3. 根据权限值,主菜单将显示按钮 3A。如果用户的权限值大于2,则用户将查看所有按钮 3B。如果用户的权限值小于2,则用户只能看到1个按钮
  4. 当我退出时,我正在使用.hide隐藏主菜单并再次显示登录表单。
  5. 我登录其他用户(权限值= 1)
  6. 所有按钮都会显示,而不仅仅是1个按钮。
  7. 有谁知道如何重做"重做"登录后的主菜单,具体取决于权限值?

2 个答案:

答案 0 :(得分:0)

也许这个?

        const int firstButtonY = 20;
        const int padding = 20;
        int currentY = firstButtonY;

        foreach (var control in this.Controls)
        {
            if (control.GetType() != typeof(System.Windows.Forms.Button))
                continue;

            var curButton = (Button) control;

            if (!curButton.Visible)
                continue;

            curButton.Top = currentY;
            currentY += padding + curButton.Height;

        }

答案 1 :(得分:0)

而不是在Form1_Load

中的Form1中打开新实例(在我的情况下,Form3)
frm3 = new Form3(this);

并在指定的事件触发器

之后显示
frm3.Show();

并取消Form3_Closing

private void Form3_FormClosing(object sender, FormClosingEventArgs e)
{
     e.Cancel = true;
     this.Hide();
}

我们为每个触发的事件

都喜欢这个
frm3 = new Form3(this);
frm3.Show();

并在Form1_Load

中评论创建新实例
//frm3 = new Form3(this);

并评论隐藏form3部分

private void Form3_FormClosing(object sender, FormClosingEventArgs e)
{
    //e.Cancel = true;
    //this.Hide();
}

因为form frm3.Show() 之后的this.Hide()不会触发

private void Form3_Load(object sender, EventArgs e)