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