如何显示一个非激活窗体
在WinForm程序中如何显示一个非激活的窗体呢?
在.NET中似乎很难做到这一点,我们需要借助ShowWindow这个API来实现:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
[DllImport("user32.dll")]
static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Form2 form2 = new Form2();
ShowWindow(form2.Handle, 4);//显示一个SW_SHOWNOACTIVATE的窗体
}
}
}
在.NET中似乎很难做到这一点,我们需要借助ShowWindow这个API来实现:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
[DllImport("user32.dll")]
static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Form2 form2 = new Form2();
ShowWindow(form2.Handle, 4);//显示一个SW_SHOWNOACTIVATE的窗体
}
}
}