Winform如何弹出窗体不是在最前面

mychinabc 2011-11-04 11:14:03
每次弹出新窗体系统都自动的选中当前窗口,如果像QQ和Tips一样只是弹出窗体显示信息,而不变成当前窗口?
不知道怎么描述,就是像QQ登录后有新闻弹在右下角的一样这种。
...全文
745 20 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
20 条回复
切换为时间正序
请发表友善的回复…
发表回复
北京的雾霾天 2011-11-16
  • 打赏
  • 举报
回复
在窗体代码里加入如下的代码:

protected override bool ShowWithoutActivation
{
get
{
return true;
}
}
zhzhzhchch 2011-11-16
  • 打赏
  • 举报
回复
让新show出来的窗体失去焦点
Daqing 2011-11-16
  • 打赏
  • 举报
回复
this.focus();
白鸽 2011-11-16
  • 打赏
  • 举报
回复
要开独立线程来实现!要不你弹出的窗体肯定要和你的主窗体占用主线程,这样自然会挡住你的主窗体了,
幽冥雨丝 2011-11-16
  • 打赏
  • 举报
回复
show之后把焦点放在当前窗口,设置弹出窗口的位置在右下角就行了
铜臂阿铁木 2011-11-16
  • 打赏
  • 举报
回复
[Quote=引用 12 楼 hbxtlhx 的回复:]

在窗体代码里加入如下的代码:

protected override bool ShowWithoutActivation
{
get
{
return true;
}
}
[/Quote]

正解 正解
allen0118 2011-11-16
  • 打赏
  • 举报
回复
这个仿照QQ做的局域网聊天程序里面的,收到信息后在右下角弹出一个小框框提示用户收到信息:

private void ShowNotifyIcon(int ShowClass, string title, string content)
{
if (title == "") title = "新消息";
CustomUIControls.TaskbarNotifier taskbarNotifier = new TaskbarNotifier();
switch (ShowClass)
{
case 1:
taskbarNotifier.SetBackgroundBitmap(new Bitmap(GetType(), "skin.bmp"), Color.FromArgb(255, 0, 255));
taskbarNotifier.SetCloseBitmap(new Bitmap(GetType(), "close.bmp"), Color.FromArgb(255, 0, 255), new Point(127, 8));
taskbarNotifier.TitleRectangle = new Rectangle(40, 9, 70, 25);
taskbarNotifier.ContentRectangle = new Rectangle(8, 41, 133, 68);
//taskbarNotifier1.TitleClick+=new EventHandler(TitleClick);
//taskbarNotifier1.ContentClick+=new EventHandler(ContentClick);
//taskbarNotifier1.CloseClick+=new EventHandler(CloseClick);
break;
case 2:
taskbarNotifier.SetBackgroundBitmap(new Bitmap(GetType(), "skin2.bmp"), Color.FromArgb(255, 0, 255));
taskbarNotifier.SetCloseBitmap(new Bitmap(GetType(), "close2.bmp"), Color.FromArgb(255, 0, 255), new Point(300, 74));
taskbarNotifier.TitleRectangle = new Rectangle(123, 80, 176, 16);
taskbarNotifier.ContentRectangle = new Rectangle(116, 97, 197, 22);
//taskbarNotifier2.TitleClick+=new EventHandler(TitleClick);
//taskbarNotifier2.ContentClick+=new EventHandler(ContentClick);
//taskbarNotifier2.CloseClick+=new EventHandler(CloseClick);
break;
case 3:
taskbarNotifier.SetBackgroundBitmap(new Bitmap(GetType(), "skin3.bmp"), Color.FromArgb(255, 0, 255));
//taskbarNotifier.SetCloseBitmap(new Bitmap(GetType(), "close.bmp"), Color.FromArgb(255, 0, 255), new Point(280, 57));
taskbarNotifier.SetCloseBitmap(new Bitmap(GetType(), "close.bmp"), Color.FromArgb(255, 0, 255), new Point(272, 42));
taskbarNotifier.TitleRectangle = new Rectangle(150, 57, 125, 28);
taskbarNotifier.ContentRectangle = new Rectangle(75, 92, 215, 55);
break;
}
taskbarNotifier.Show(title, content, 500, 3000, 500);
}
feng_3630 2011-11-16
  • 打赏
  • 举报
回复
设置窗体的TopLevel=false
小志 2011-11-16
  • 打赏
  • 举报
回复
用API函数:
[DllImport("user32.dll")]
public static extern Boolean ShowWindow(IntPtr hWnd, Int32 nCmdShow);//显示窗口
调用:
Form1 f = new Form1();
ShowWindow(f.Handle,4);
jshi123 2011-11-16
  • 打赏
  • 举报
回复

private const int SW_SHOWNOACTIVATE = 4;
private const int HWND_TOPMOST = -1;
private const uint SWP_NOACTIVATE = 0x0010;

[DllImport("user32.dll", EntryPoint = "SetWindowPos")]
static extern bool SetWindowPos(IntPtr hWnd, int hWndInsertAfter, int x, int y, int cx, int cy, uint uFlags);

[DllImport("user32.dll")]
static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);

static void ShowInactiveTopmost(Form frm)
{
ShowWindow(frm.Handle, SW_SHOWNOACTIVATE);
SetWindowPos(frm.Handle, HWND_TOPMOST, frm.Left, frm.Top, frm.Width, frm.Height, SWP_NOACTIVATE);
}

xiaoid 2011-11-16
  • 打赏
  • 举报
回复

12楼的答案是正确的.
ijwsoft 2011-11-16
  • 打赏
  • 举报
回复
form1.Show();
form1.BringToFront();
q198708wyp 2011-11-14
  • 打赏
  • 举报
回复
我有弹出消息的例子,跟QQ差不多 弹出五秒不动自动消失 ,而且还有锁定的功能 邮箱留下 我发你 楼主
阿非 2011-11-14
  • 打赏
  • 举报
回复
show 之后 设置焦点在本窗口
mychinabc 2011-11-14
  • 打赏
  • 举报
回复
顶下,有其它方法不?
mabaolin 2011-11-04
  • 打赏
  • 举报
回复
new出以后,焦点放到别处。不能showdialog
javabegin 2011-11-04
  • 打赏
  • 举报
回复
弹出窗口不要ShowDialog,只是Show。
bdmh 2011-11-04
  • 打赏
  • 举报
回复
还可以设置topmost属性
如此 2011-11-04
  • 打赏
  • 举报
回复

Form2 f2 = new Form2();
f2.Show();
this.Focus();
//在form2中通过设置 this.StartPosition属性决定窗体的起始位置.

111,098

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧