using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
namespace WindowsFormsApplication4
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public class WindowWrapper : System.Windows.Forms.IWin32Window
{
public WindowWrapper(IntPtr handle)
{
_hwnd = handle;
}
public IntPtr Handle
{
get { return _hwnd; }
}
private IntPtr _hwnd;
}
private void button1_Click(object sender, EventArgs e)
{
Form3 form3 = new Form3();
form3.ShowDialog(); // 等价于 form3.ShowDialog(this);
}
private void button2_Click(object sender, EventArgs e)
{
Form2 form2 = new Form2();
form2.Show();
Form3 form3 = new Form3();
form3.ShowDialog(form2); //指定父窗体
}
private void button3_Click(object sender, EventArgs e)
{
//需要引入System.Diagnostics命名空间
Process[] procs = Process.GetProcessesByName("Notepad");
if (procs.Length != 0)
{
IntPtr hwnd = procs[0].MainWindowHandle;
Form3 form3 = new Form3();
//WindowWrapper类见下面
form3.ShowDialog(new WindowWrapper(hwnd)); //指定记事本为父窗体
}
}
}
}
阅读(1896) | 评论(0) | 转发(0) |