简体   繁体   English

在任务栏中最小化表单时将其放在最前面

[英]Bringing a form to front when it is minimized in taskbar

Is there a way to bring a form that is already minimized to taksbar to front? 有没有办法将已经最小化的表格带到Taksbar前面? I have tried the codes below but no success: 我尝试了以下代码,但未成功:

        filterForm.Show();
        filterForm.Activate();
        filterForm.BringToFront();

PS: This form is called from another form, and user do some stuff in it and then may minimize it. PS:此表单是从另一个表单中调用的,用户在其中进行了一些处理,然后可以将其最小化。 I want only a single instance of this form to be open at a time, so the second time user clicks the button for showing the form I am checking if the form is already shown or not, if shown I want it to be in front: 我希望一次仅打开此表单的一个实例,因此用户第二次单击该按钮以显示该表单。我正在检查该表单是否已显示,如果显示,则希望其位于前面:

public FilterForm filterForm;
public bool IsFilterFormActive;

private void tsOpenFilerForm_Click(object sender, EventArgs e)
{
    if (!IsFilterFormActive)
    {
        filterForm = new FilterForm();
        filterForm.FormClosing += delegate {
                                               IsFilterFormActive = false;
                                            };
        IsFilterFormActive = true;
        filterForm.Show();
    }
    else
    {
        filterForm.Show();
        filterForm.Activate();
        filterForm.BringToFront();
    }
}

You are leaking the form instance, best thing to do is setting it back to null when it closes. 您正在泄漏表单实例,最好的办法是在关闭它时将其设置回null。 You then don't need the bool either. 然后,您也不需要布尔。 Like this: 像这样:

    FilterForm filterForm;

    private void tsFilterForm_Click(object sender, EventArgs e) {
        if (filterForm == null) {
            filterForm = new FilterForm();
            filterForm.FormClosed += delegate { filterForm = null; };
            filterForm.Show();
        }
        else {
            filterForm.WindowState = FormWindowState.Normal;
            filterForm.Focus();
        }
    }

Add filterForm.WindowState = FormWindowState.Normal; 添加filterForm.WindowState = FormWindowState.Normal; before in order to restore the window. 之前为了还原窗口。 If its minimized you first have to bring it up again. 如果将其最小化,则必须首先重新启动它。 Then filterForm.Activate() should be enough. 然后filterForm.Activate()应该足够了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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