代码之家  ›  专栏  ›  技术社区  ›  HardCode

不透明表单覆盖,不覆盖任务栏

  •  0
  • HardCode  · 技术社区  · 14 年前

    OpaqueForm将FormBorderStyle属性设置为None,并在构造函数中接受它调用.ShowDialog的窗体对象。效果很好,但有一个警告。任务栏也被不透明窗体覆盖;我假设是因为它的FormBorderStyle为None,WindowState为Maximized。

    我不希望不透明窗体覆盖任务栏,因为让我的模态窗体阻止用户在任务之间切换是不礼貌的。我该如何防止不透明窗体也覆盖任务栏,同时仍然使用FormBorderStyle为None?

    4 回复  |  直到 14 年前
        1
  •  1
  •   Hans Passant    14 年前

    我不知道怎么会这样。只需确保覆盖显示为Show(owner),以便它始终位于顶部,并且它的大小和位置与覆盖窗体完全相同。

    this thread

        2
  •  1
  •   McKay    14 年前

    为什么不在另一个窗体的顶部放置一个“不透明”面板呢。让整个用户窗口不透明是没有意义的。因为如果应用程序没有最大化地运行,他们会希望单击其他应用程序。

        3
  •  0
  •   Alex Essilfie    14 年前

    将窗体的大小设置为屏幕的工作区域。

    Dim f as New Form()
    f.FormBorderStyle = FormBorderStyle.None
    f.Location = New Point(0, 0)
    f.Size = My.Computer.Screen.WorkingArea.Size
    



    如果需要将不透明窗体放置在 主屏幕 ,使用以下代码:

    For Each scr In Screen.AllScreens
        If scr.Primary = True Then
            Dim f As New Form()
            f.FormBorderStyle = FormBorderStyle.None
            f.Location = New Point(0, 0)
            f.Size = scr.WorkingArea.Size
        End If
    Next
    

        4
  •  0
  •   edhubbell    10 年前

    我有一个.ShowDialog()语句,导致子窗体显示得足够大,以至于它覆盖了任务栏。

    结果,问题是我在子窗体代码中将MaximizeBox和MaximizeBox都设置为False。不知道为什么,但将其更改为MaximizeBox=True可以使maximized表单停止侵入任务栏区域。

        5
  •  -1
  •   Muthaiah Balasubramaniam    5 年前

    #region Windows Form Designer generated code
    
    private void InitializeComponent()
    {
        this.components = new System.ComponentModel.Container();
        this.SuspendLayout();
        // 
        // TransparentForm
        // 
        this.AccessibleRole = System.Windows.Forms.AccessibleRole.None;
        this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.ClientSize = new System.Drawing.Size(284, 261);
        this.ControlBox = false;
        this.DoubleBuffered = true;
        this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
        this.Location = new System.Drawing.Point(70, 70);
        this.MaximizeBox = false;
        this.MinimizeBox = false;
        this.Name = "TransparentForm";
        this.Opacity = 0D;
        this.ShowIcon = false;
        this.ShowInTaskbar = false;
        this.Text = "TransparentForm";
        this.TransparencyKey = System.Drawing.Color.FromArgb(((int)(((byte)(224)))), ((int)(((byte)(224)))), ((int)(((byte)(224)))));
        this.Load += new System.EventHandler(this.TransparentForm_Load);
        this.ResumeLayout(false);
    
    }
    

    private void TransparentForm_Load(object sender, EventArgs e)
    {
        Form f = Application.OpenForms[<yourapplication's main form>];
        this.Width = f.Width;
        this.Height = f.Height;
        this.Location = f.Location;
        this.Opacity = 0.01D;
    }
    

    希望这有帮助。。

    穆塔亚B