使用Visual Studio 2008和VB.NET ...
我创建了一个表单(OpaqueForm),这是我将用ShowDialog打开的其他表单之间的中间形式。我的想法是,当我想使用.ShowDialog显示一个表单时,这个OpaqueForm(不透明度不是100%)位于主窗体和对话框窗体之间,有效地“灰化”底层主窗体。
OpaqueForm将FormBorderStyle属性设置为None,并在构造函数中接受一个Form对象,在该对象上调用.ShowDialog。效果很好,但有一点需要注意。任务栏也包含在OpaqueForm中;我假设因为它的FormBorderStyle为None且WindowState为Maximized。
我不希望OpaqueForm覆盖任务栏,因为让我的模态形式锁定用户在任务之间切换是不礼貌的。我怎么能防止OpaqueForm覆盖任务栏,同时仍然使用FormBorderStyle为None?
答案 0 :(得分:1)
为什么不在另一个表单的顶部放置一个“不透明”面板。使整个用户窗口不透明是没有意义的。因为如果应用程序未运行最大化,他们将需要单击其他应用程序。
答案 1 :(得分:1)
我不确定这是怎么发生的。只需确保叠加显示为显示(所有者),以便它始终位于顶部,并且它具有与叠加形式完全相同的大小和位置。
您可以在this thread的答案中找到此类叠加层的示例代码。
答案 2 :(得分:0)
将表单大小的大小设置为屏幕的工作区域。
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
如果您想在每个屏幕上放置一个表单,只需删除条件就跳过检查主屏幕。
答案 3 :(得分:0)
我有一个.ShowDialog()语句,导致子窗体显示得足够大,覆盖了任务栏。
事实证明,问题是我在子表单代码中将MaximizeBox都设置为False。不知道为什么,但改变它以使MaximizeBox = True使最大化的形式停止侵入任务栏区域。
答案 4 :(得分:-1)
请尝试这段代码:
#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;
}
希望这会有所帮助。
Muthaiah B