【问题标题】:C# Form popup locationC# 窗体弹出位置
【发布时间】:2016-09-23 03:34:01
【问题描述】:

我正在构建一个弹出应用程序来显示一些通知。我想以任何屏幕分辨率在右下角的屏幕上显示它。屏幕尺寸为 422 x 217(宽 x 高)。这是我的代码:

private void Form1_Load(object sender, EventArgs e)
    {
        /*System.Windows.Forms.Timer MyTimer = new System.Windows.Forms.Timer(); */

        int num = 1;
        this.Hide();
        if (num == 1)
        {
            Form fm = new Form
            {
                Location = new Point(50, 60),
                StartPosition = FormStartPosition.Manual,
                ShowInTaskbar = false
            };
            fm.ShowDialog();
        }
    }

我想让弹出窗口从底部弹出。谁能帮我解决这个问题?

【问题讨论】:

    标签: c# forms popup location


    【解决方案1】:

    我最近得到了一个“烤面包机”弹出窗口的代码,它从任何屏幕的右下角弹出。这是我使用的代码隐藏的一部分:

    Dispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle, new Action(() =>
                {
                    var workingArea = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea;
                    var transform = PresentationSource.FromVisual(this).CompositionTarget.TransformFromDevice;
                    var corner = transform.Transform(new Point(workingArea.Right + 15, workingArea.Bottom - 10));
    
                    this.Left = corner.X - this.ActualWidth - 100;
                    this.Topmost = true;
                    this.Top = corner.Y - this.ActualHeight;
    
                }));
    

    根据您的“弹出”尺寸调整-100+15-10

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多