C# winforms中的弹出窗口(但未注册为新的独立窗口)
我想在我的主窗体上的屏幕上显示信息消息 我的问题是,我不想在windows中注册为新表单,因为在应用程序之间切换时,它会显示在任务栏上。我有很多这样的信息框弹出来通知你的事件 其思想是,它的工作原理应该类似于对话框,除非它不希望您与对话框交互,否则不要注册为独立表单 到目前为止,我使用以下方法:C# winforms中的弹出窗口(但未注册为新的独立窗口),c#,winforms,C#,Winforms,我想在我的主窗体上的屏幕上显示信息消息 我的问题是,我不想在windows中注册为新表单,因为在应用程序之间切换时,它会显示在任务栏上。我有很多这样的信息框弹出来通知你的事件 其思想是,它的工作原理应该类似于对话框,除非它不希望您与对话框交互,否则不要注册为独立表单 到目前为止,我使用以下方法: var notification = new Notification(); notification.ShowInTaskbar = false; notification.Show();
var notification = new Notification();
notification.ShowInTaskbar = false;
notification.Show();
internal class WindowsExtendedStyles
{
public const int WS_EX_DLGMODALFRAME = 0x00000001;
public const int WS_EX_NOPARENTNOTIFY = 0x00000004;
public const int WS_EX_TOPMOST = 0x00000008;
public const int WS_EX_ACCEPTFILES = 0x00000010;
public const int WS_EX_TRANSPARENT = 0x00000020;
public const int WS_EX_MDICHILD = 0x00000040;
public const int WS_EX_TOOLWINDOW = 0x00000080;
public const int WS_EX_WINDOWEDGE = 0x00000100;
public const int WS_EX_CLIENTEDGE = 0x00000200;
public const int WS_EX_CONTEXTHELP = 0x00000400;
public const int WS_EX_RIGHT = 0x00001000;
public const int WS_EX_LEFT = 0x00000000;
public const int WS_EX_RTLREADING = 0x00002000;
public const int WS_EX_LTRREADING = 0x00000000;
public const int WS_EX_LEFTSCROLLBAR = 0x00004000;
public const int WS_EX_RIGHTSCROLLBAR = 0x00000000;
public const int WS_EX_CONTROLPARENT = 0x00010000;
public const int WS_EX_STATICEDGE = 0x00020000;
public const int WS_EX_APPWINDOW = 0x00040000;
public const int WS_EX_OVERLAPPEDWINDOW = WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE;
public const int WS_EX_PALETTEWINDOW = WS_EX_WINDOWEDGE | WS_EX_TOOLWINDOW | WS_EX_TOPMOST;
public const int WS_EX_LAYERED = 0x00080000;
public const int WS_EX_NOINHERITLAYOUT = 0x00100000; // Disable inheritence of mirroring by children
public const int WS_EX_LAYOUTRTL = 0x00400000; // Right to left mirroring
public const int WS_EX_COMPOSITED = 0x02000000;
public const int WS_EX_NOACTIVATE = 0x08000000;
}
internal class MouseActivate
{
public const int MA_ACTIVATE = 1;
public const int MA_ACTIVATEANDEAT = 2;
public const int MA_NOACTIVATE = 3;
public const int MA_NOACTIVATEANDEAT = 4;
}
有人能指出如何防止此窗口注册为独立窗口吗
编辑:感谢推荐链接@shf301:
我看了一下,但没有关系。该链接说明如何从alt tab菜单隐藏应用程序。在本例中,我不想隐藏我的应用程序,我只想显示弹出窗口,而不将其注册为新窗口。我知道的在程序中显示窗口而不显示在任务栏中的唯一方法是使用多文档界面MDI。这有点复杂,但可以完成您想要的任务:在窗口中显示窗口
有关.NET中MDI的更多信息:我所知道的在程序中显示窗口而不显示在任务栏中的唯一方法是使用多文档界面MDI。这有点复杂,但可以完成您想要的任务:在窗口中显示窗口
有关.NET中MDI的更多信息:这并不容易,因为windows窗体基本上不支持弹出窗口。虽然windows窗体基于win32,但支持win32弹出窗口。 如果您接受了一些技巧,下面的代码将设置一个弹出窗口。您决定是否要充分利用它: 这是创建实例工具提示的方式
class PopupWindow : Control
{
private const int WM_ACTIVATE = 0x0006;
private const int WM_MOUSEACTIVATE = 0x0021;
private Control ownerControl;
public PopupWindow(Control ownerControl)
:base()
{
this.ownerControl = ownerControl;
base.SetTopLevel(true);
}
public Control OwnerControl
{
get
{
return (this.ownerControl as Control);
}
set
{
this.ownerControl = value;
}
}
protected override CreateParams CreateParams
{
get
{
CreateParams createParams = base.CreateParams;
createParams.Style = WindowStyles.WS_POPUP |
WindowStyles.WS_VISIBLE |
WindowStyles.WS_CLIPSIBLINGS |
WindowStyles.WS_CLIPCHILDREN |
WindowStyles.WS_MAXIMIZEBOX |
WindowStyles.WS_BORDER;
createParams.ExStyle = WindowsExtendedStyles.WS_EX_LEFT |
WindowsExtendedStyles.WS_EX_LTRREADING |
WindowsExtendedStyles.WS_EX_RIGHTSCROLLBAR |
WindowsExtendedStyles.WS_EX_TOPMOST;
createParams.Parent = (this.ownerControl != null) ? this.ownerControl.Handle : IntPtr.Zero;
return createParams;
}
}
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
public static extern IntPtr SetActiveWindow(HandleRef hWnd);
protected override void WndProc(ref Message m)
{
switch (m.Msg)
{
case WM_ACTIVATE:
{
if ((int)m.WParam == 1)
{
//window is being activated
if (ownerControl != null)
{
SetActiveWindow(new HandleRef(this, ownerControl.FindForm().Handle));
}
}
break;
}
case WM_MOUSEACTIVATE:
{
m.Result = new IntPtr(MouseActivate.MA_NOACTIVATE);
return;
//break;
}
}
base.WndProc(ref m);
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
e.Graphics.FillRectangle(SystemBrushes.Info, 0, 0, Width, Height);
e.Graphics.DrawString((ownerControl as VerticalDateScrollBar).FirstVisibleDate.ToLongDateString(), this.Font, SystemBrushes.InfoText, 2, 2);
}
}
对它进行一点实验,你必须摆弄它的位置和大小。错误地使用它,什么也看不出来。这并不容易,因为windows窗体基本上不支持弹出窗口。虽然windows窗体基于win32,但支持win32弹出窗口。 如果您接受了一些技巧,下面的代码将设置一个弹出窗口。您决定是否要充分利用它: 这是创建实例工具提示的方式
class PopupWindow : Control
{
private const int WM_ACTIVATE = 0x0006;
private const int WM_MOUSEACTIVATE = 0x0021;
private Control ownerControl;
public PopupWindow(Control ownerControl)
:base()
{
this.ownerControl = ownerControl;
base.SetTopLevel(true);
}
public Control OwnerControl
{
get
{
return (this.ownerControl as Control);
}
set
{
this.ownerControl = value;
}
}
protected override CreateParams CreateParams
{
get
{
CreateParams createParams = base.CreateParams;
createParams.Style = WindowStyles.WS_POPUP |
WindowStyles.WS_VISIBLE |
WindowStyles.WS_CLIPSIBLINGS |
WindowStyles.WS_CLIPCHILDREN |
WindowStyles.WS_MAXIMIZEBOX |
WindowStyles.WS_BORDER;
createParams.ExStyle = WindowsExtendedStyles.WS_EX_LEFT |
WindowsExtendedStyles.WS_EX_LTRREADING |
WindowsExtendedStyles.WS_EX_RIGHTSCROLLBAR |
WindowsExtendedStyles.WS_EX_TOPMOST;
createParams.Parent = (this.ownerControl != null) ? this.ownerControl.Handle : IntPtr.Zero;
return createParams;
}
}
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
public static extern IntPtr SetActiveWindow(HandleRef hWnd);
protected override void WndProc(ref Message m)
{
switch (m.Msg)
{
case WM_ACTIVATE:
{
if ((int)m.WParam == 1)
{
//window is being activated
if (ownerControl != null)
{
SetActiveWindow(new HandleRef(this, ownerControl.FindForm().Handle));
}
}
break;
}
case WM_MOUSEACTIVATE:
{
m.Result = new IntPtr(MouseActivate.MA_NOACTIVATE);
return;
//break;
}
}
base.WndProc(ref m);
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
e.Graphics.FillRectangle(SystemBrushes.Info, 0, 0, Width, Height);
e.Graphics.DrawString((ownerControl as VerticalDateScrollBar).FirstVisibleDate.ToLongDateString(), this.Font, SystemBrushes.InfoText, 2, 2);
}
}
对它进行一点实验,你必须摆弄它的位置和大小。使用错误,没有显示。 如果您正在寻找的通知需要支持用户交互,则可以考虑使用控件显示弹出窗口并在.< /p>中托管控件。
或者,它们中的一个应该只是显示信息,没有用户交互,使用with Balloon=true控件。您也可以通过自定义绘制它的内容来定制它的视觉效果。 < P>如果您正在寻找的通知需要支持用户交互,您可以考虑使用控件显示弹出窗口并在./P>中托管控件。
或者,它们中的一个应该只是显示信息,没有用户交互,使用with Balloon=true控件。您还可以通过自定义内容来自定义其视觉效果。@Philip的答案是正确的 我必须补充以下内容:
var notification = new Notification();
notification.ShowInTaskbar = false;
notification.Show();
internal class WindowsExtendedStyles
{
public const int WS_EX_DLGMODALFRAME = 0x00000001;
public const int WS_EX_NOPARENTNOTIFY = 0x00000004;
public const int WS_EX_TOPMOST = 0x00000008;
public const int WS_EX_ACCEPTFILES = 0x00000010;
public const int WS_EX_TRANSPARENT = 0x00000020;
public const int WS_EX_MDICHILD = 0x00000040;
public const int WS_EX_TOOLWINDOW = 0x00000080;
public const int WS_EX_WINDOWEDGE = 0x00000100;
public const int WS_EX_CLIENTEDGE = 0x00000200;
public const int WS_EX_CONTEXTHELP = 0x00000400;
public const int WS_EX_RIGHT = 0x00001000;
public const int WS_EX_LEFT = 0x00000000;
public const int WS_EX_RTLREADING = 0x00002000;
public const int WS_EX_LTRREADING = 0x00000000;
public const int WS_EX_LEFTSCROLLBAR = 0x00004000;
public const int WS_EX_RIGHTSCROLLBAR = 0x00000000;
public const int WS_EX_CONTROLPARENT = 0x00010000;
public const int WS_EX_STATICEDGE = 0x00020000;
public const int WS_EX_APPWINDOW = 0x00040000;
public const int WS_EX_OVERLAPPEDWINDOW = WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE;
public const int WS_EX_PALETTEWINDOW = WS_EX_WINDOWEDGE | WS_EX_TOOLWINDOW | WS_EX_TOPMOST;
public const int WS_EX_LAYERED = 0x00080000;
public const int WS_EX_NOINHERITLAYOUT = 0x00100000; // Disable inheritence of mirroring by children
public const int WS_EX_LAYOUTRTL = 0x00400000; // Right to left mirroring
public const int WS_EX_COMPOSITED = 0x02000000;
public const int WS_EX_NOACTIVATE = 0x08000000;
}
internal class MouseActivate
{
public const int MA_ACTIVATE = 1;
public const int MA_ACTIVATEANDEAT = 2;
public const int MA_NOACTIVATE = 3;
public const int MA_NOACTIVATEANDEAT = 4;
}
@菲利普的回答是正确的 我必须补充以下内容:
var notification = new Notification();
notification.ShowInTaskbar = false;
notification.Show();
internal class WindowsExtendedStyles
{
public const int WS_EX_DLGMODALFRAME = 0x00000001;
public const int WS_EX_NOPARENTNOTIFY = 0x00000004;
public const int WS_EX_TOPMOST = 0x00000008;
public const int WS_EX_ACCEPTFILES = 0x00000010;
public const int WS_EX_TRANSPARENT = 0x00000020;
public const int WS_EX_MDICHILD = 0x00000040;
public const int WS_EX_TOOLWINDOW = 0x00000080;
public const int WS_EX_WINDOWEDGE = 0x00000100;
public const int WS_EX_CLIENTEDGE = 0x00000200;
public const int WS_EX_CONTEXTHELP = 0x00000400;
public const int WS_EX_RIGHT = 0x00001000;
public const int WS_EX_LEFT = 0x00000000;
public const int WS_EX_RTLREADING = 0x00002000;
public const int WS_EX_LTRREADING = 0x00000000;
public const int WS_EX_LEFTSCROLLBAR = 0x00004000;
public const int WS_EX_RIGHTSCROLLBAR = 0x00000000;
public const int WS_EX_CONTROLPARENT = 0x00010000;
public const int WS_EX_STATICEDGE = 0x00020000;
public const int WS_EX_APPWINDOW = 0x00040000;
public const int WS_EX_OVERLAPPEDWINDOW = WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE;
public const int WS_EX_PALETTEWINDOW = WS_EX_WINDOWEDGE | WS_EX_TOOLWINDOW | WS_EX_TOPMOST;
public const int WS_EX_LAYERED = 0x00080000;
public const int WS_EX_NOINHERITLAYOUT = 0x00100000; // Disable inheritence of mirroring by children
public const int WS_EX_LAYOUTRTL = 0x00400000; // Right to left mirroring
public const int WS_EX_COMPOSITED = 0x02000000;
public const int WS_EX_NOACTIVATE = 0x08000000;
}
internal class MouseActivate
{
public const int MA_ACTIVATE = 1;
public const int MA_ACTIVATEANDEAT = 2;
public const int MA_NOACTIVATE = 3;
public const int MA_NOACTIVATEANDEAT = 4;
}
您可以使用MDI表单??尝试将其传递给Show方法。可能重复的我不明白为什么这与该问题重复。可能重复的您可以使用MDI表单??尝试将其传递给Show方法。可能重复的我不明白为什么这与该问题重复。可能重复的谢谢,我知道MDI窗口,但在我的情况下这不是一个选项。谢谢,我知道MDI窗口,但在我的情况下这不是一个选项。感谢Philip提供了快速而出色的答案。任何使用它的人。。请参阅下面我的帖子以获取更多代码。感谢Philip快速而出色的回答。任何使用它的人。。请参阅下面我的帖子以了解更多代码。