c# - 表格位置不对

标签 c# winforms topmost form-control

我想在特定时间显示一个表单类的实例。表格需要放在最上面,而不是抢走焦点。这是我的代码:

public class mSplashForm : Form
{
    public mSplashForm()
    {
        this.FormBorderStyle = FormBorderStyle.None;
        this.BackColor = Color.LightBlue;
        this.Opacity = 0.92D;
        this.ShowInTaskbar = false;
        this.MinimumSize = new System.Drawing.Size(5, 5);
    }
}


public static void mSplash(int time = 500)
{
    mSplashForm SF = new mSplashForm();
    Application.EnableVisualStyles();
    SF.Width = 500;
    SF.Height = 100;
    SF.Left = 500;
    SF.Top = 500;
    SetWindowPos(SF.Handle, HWND_TOPMOST, SF.Left, SF.Top, SF.Width, SF.Height, SWP_NOACTIVATE);
    ShowWindow(SF.Handle, mEnumShowWindowCommands.ShowNoActivate);
    Application.DoEvents();
    Thread.Sleep(time);
    SF.Close();
}

有效,但表单未显示在使用 Top 和 Left 参数定义的正确位置。请问有什么问题吗?

最佳答案

您已将表单设置为从 FormStartPosition.WindowsDefaultLocation 开始。将此添加到您的 mSplash 函数中:

SF.StartPosition = FormStartPosition.Manual;

这就是为什么它会尝试在每个打开的页面上连续定位(根据您的评论)。

关于c# - 表格位置不对,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25111442/

相关文章:

c# - 如何调用WebMethod?

c# - 如何写入嵌入式资源?

vb.net - ReportViewer.LocalReport.Render ("PDF")

powershell - 在 PowerShell 中将控制台设置为 Top-Most

c# - 尝试,捕获问题

C#如何取消一个正在执行的方法

c# - 如何避免 Winforms 中 ToolStrip 左侧出现 3 个像素间隙?

C# GDI - 如何创建多边形(点集)的位图副本

c# - 如何获取 WinForm 应用程序中最顶层窗体的句柄?

c# - 如何将 MDI 子窗体带到前面?