c# - 如何将 Windows 窗体置顶?

标签 c# winforms

<分区>

我正在用 C# 开发 Windows 窗体应用程序。当一种特殊的外部事件发生时,此应用程序会在表单上显示一些文本(例如,假设我想在鼠标位置 y=0 时在表单上写“鼠标在上一行”)。当事件发生时,我需要将表单置于所有其他窗口的顶部。

最佳答案

在你的表单类中使用它:

public void BringToTop()
{
    //Checks if the method is called from UI thread or not
    if (this.InvokeRequired)
    {
        this.Invoke(new Action(BringToTop));
    }
    else
    {
        if (this.WindowState == FormWindowState.Minimized)
        {
            this.WindowState = FormWindowState.Normal;
        }
        //Keeps the current topmost status of form
        bool top = TopMost;
        //Brings the form to top
        TopMost = true;
        //Set form's topmost status back to whatever it was
        TopMost = top;
    }
}

关于c# - 如何将 Windows 窗体置顶?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31981187/

相关文章:

c# - Entity Framework : Insert causes violation of PRIMARY KEY constraint using Azure SQL, 不是本地的

c# - 多行文本框根据文本量自动调整高度

c# - 如何使用 TreeView.Tag = object?

c# - 如何在文本框中设置光标位置

c# - 如何将按钮字体设置为 Marlett

c# - 是否可以覆盖 ASP.NET MVC 中 [Authorize] 的默认行为?

c# - 如何从 dotnetnuke 获取完整的 url

c# - 在 WPF 中将窗口置于最前面

c# - 如何使用 JSON.Net 遍历 JObject 键的 JProperties

c# - 如何在 WinForms、GDI+ 中绘制和填充像素完美的对称椭圆?