C# 如何让最顶端的窗口必须操作

jimeixuehua 2010-05-10 07:05:02
就像 MessageBox窗口那样 ,如果不点确定 ,就无法操作其他的窗口,请高手赐教呀!在线等!!!!!
...全文
164 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
lxp116 2010-05-10
  • 打赏
  • 举报
回复
ShowDialog
mngzilin 2010-05-10
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 zenghd 的回复:]
ShowDialog
[/Quote]。
ZengHD 2010-05-10
  • 打赏
  • 举报
回复
那就试试11楼的方法
jimeixuehua 2010-05-10
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 zenghd 的回复:]
C# code

第3,使用单例只出现一个窗体
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

……
[/Quote]
我是想要,只让某个子窗口在父窗口中只有一个实例!谢谢了
jimeixuehua 2010-05-10
  • 打赏
  • 举报
回复
[Quote=引用 12 楼 wuyq11 的回复:]
BOOL SetForegroundWindow(
HWND hWnd
);
ShowDialog()
B b = new B();
b.ShowDialog(this);
[DllImport("user32.dll", EntryPoint = "FindWindow")]
private extern static IntPtr FindWindow(string l……
[/Quote]
看不懂呀
wuyq11 2010-05-10
  • 打赏
  • 举报
回复
BOOL SetForegroundWindow(
HWND hWnd
);
ShowDialog()
B b = new B();
b.ShowDialog(this);
[DllImport("user32.dll", EntryPoint = "FindWindow")]
private extern static IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll")]
static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);

private void button1_Click(object sender, EventArgs e)
{
IntPtr hWnd1 = FindWindow(null, "主窗口标题");
SetForegroundWindow(hWnd1);
}

ZengHD 2010-05-10
  • 打赏
  • 举报
回复

第3,使用单例只出现一个窗体
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication1
{
public partial class Form2 : Form
{
private Form2()
{
InitializeComponent();
}

private static Form2 MyForm = new Form2();

public static void MyShow()
{
if (MyForm == null || MyForm.IsDisposed)
MyForm = new Form2();
MyForm.Show();
MyForm.Activate();
}
}
}
ZengHD 2010-05-10
  • 打赏
  • 举报
回复

第2指定标题
[DllImport("User32.dll", EntryPoint = "SendMessage")]
private static extern int SendMessage(
int hWnd,
int Msg,
int wParam,
int lParam
);

[DllImport("User32.dll", EntryPoint = "FindWindow")]
private static extern int FindWindow(string lpClassName, string
lpWindowName);

private static int WM_CLOSE = 0x10;

private void button1_Click(object sender, EventArgs e)
{
SendMessage(FindWindow(null,"输入要关闭窗体的标题"), WM_CLOSE, 0, 0);
}
ZengHD 2010-05-10
  • 打赏
  • 举报
回复

第1:指定句柄

private static extern int SendMessage(
int hWnd,
int Msg,
int wParam,
int lParam
);

[DllImport("User32.dll", EntryPoint = "FindWindow")]
private static extern int FindWindow(string lpClassName, string
lpWindowName);

private static int WM_CLOSE = 0x10;

private void button1_Click(object sender, EventArgs e)
{
SendMessage(输入要关闭的句子柄, WM_CLOSE, 0, 0);
}
jimeixuehua 2010-05-10
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 zenghd 的回复:]
引用 2 楼 jimeixuehua 的回复:

我在问一个问题,就是怎样关闭MID窗体中,指定的子窗体 。也就是说让子窗体只能有一个运行!!

指定?你指定什么?指定标题还是指定句柄
[/Quote]
二者都行,有代码可以演示一下吗,高手
jimeixuehua 2010-05-10
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 zenghd 的回复:]
ShowDialog
[/Quote]
非常感谢!!
cnsunwu 2010-05-10
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 zh383603842 的回复:]
哇 请设置窗口的 TosMost 为true
谢谢解答!
ZengHD 2010-05-10
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 jimeixuehua 的回复:]

我在问一个问题,就是怎样关闭MID窗体中,指定的子窗体 。也就是说让子窗体只能有一个运行!!
[/Quote]
指定?你指定什么?指定标题还是指定句柄
jimeixuehua 2010-05-10
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 zh383603842 的回复:]
哇 请设置窗口的 TosMost 为true
[/Quote]
不行呀,那样还是可以操作别的窗体,我的意思是必须操作完最顶层的那个窗体后,才能操作别的窗体,就像IE浏览器的【设置】窗体一样!!!
ZengHD 2010-05-10
  • 打赏
  • 举报
回复
ShowDialog
jimeixuehua 2010-05-10
  • 打赏
  • 举报
回复
我在问一个问题,就是怎样关闭MID窗体中,指定的子窗体 。也就是说让子窗体只能有一个运行!!
永远的小鱼 2010-05-10
  • 打赏
  • 举报
回复
哇 请设置窗口的 TosMost 为true

110,499

社区成员

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

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

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