.net 不覆盖任务栏的不透明表单覆盖
使用Visual Studio 2008和VB.NET 我创建了一个表单(OpaqueForm),它是其他表单之间的中间表单,我将使用ShowDialog打开它。其思想是,当我想使用.ShowDialog显示窗体时,这个不透明的不透明窗体位于主窗体和对话框窗体之间,有效地“灰显”了底层主窗体 OpaqueForm将FormBorderStyle属性设置为None,并在构造函数中接受它调用的Form对象。ShowDialog。效果很好,但有一个警告。任务栏也包含在不透明窗体中;我之所以这样假设是因为它的FormBorderStyle为None,WindowsState为Maximized.net 不覆盖任务栏的不透明表单覆盖,.net,vb.net,winforms,.net,Vb.net,Winforms,使用Visual Studio 2008和VB.NET 我创建了一个表单(OpaqueForm),它是其他表单之间的中间表单,我将使用ShowDialog打开它。其思想是,当我想使用.ShowDialog显示窗体时,这个不透明的不透明窗体位于主窗体和对话框窗体之间,有效地“灰显”了底层主窗体 OpaqueForm将FormBorderStyle属性设置为None,并在构造函数中接受它调用的Form对象。ShowDialog。效果很好,但有一个警告。任务栏也包含在不透明窗体中;我之所以这样假设是因
我不希望不透明表单覆盖任务栏,因为让我的模式表单阻止用户在任务之间切换是不礼貌的。我如何防止不透明窗体也覆盖任务栏,同时仍然使用FormBorderStyle为None?为什么不在另一个窗体的顶部放置一个“不透明”面板呢。让整个用户窗口不透明是没有意义的。因为如果应用程序没有最大化运行,他们会希望单击其他应用程序。我不确定这是如何发生的。只需确保覆盖显示为Show(owner),使其始终位于顶部,并且其大小和位置与覆盖表单完全相同
您将在中的我的答案中找到这种覆盖的示例代码 将窗体大小设置为屏幕工作区域的大小
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
如果要在每个屏幕上放置一个表单,只需删除条件,跳过检查主屏幕即可。我有一个.ShowDialog()语句,该语句导致子表单显示得足够大,以至于覆盖了任务栏
事实证明,问题是我在子表单代码中将MaximizeBox和ebox都设置为False。不确定原因,但将其更改为MaximizeBox=True会使最大化表单停止侵入任务栏区域。请尝试以下代码:
#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);
}
现在,在TransparentForm.cs文件中包含以下代码:
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;
}
private void TransparentForm_加载(对象发送方,事件参数e)
{
Form f=应用程序。OpenForms[.ShowDialog(所有者)在调整表单大小以匹配基础表单后工作。+1-你是对的,只覆盖应用程序的表单,而不是整个用户窗口。这个多监视器兼容吗?我不这么认为。这标记为9年前回答的,当问题是关于VB.NET时,你的回答是C#。