在WinForm环境下,可以让任意组件全屏显示,仍然需要借助于P/Invoke,如下:
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
private void button1_Click(object sender, EventArgs e)
{
SetParent(panel1.Handle, IntPtr.Zero);
panel1.Left = 0;
panel1.Top = 0;
panel1.Width = Screen.PrimaryScreen.Bounds.Width;
panel1.Height = Screen.PrimaryScreen.Bounds.Height;
}
private void button2_Click(object sender, EventArgs e)
{
SetParent(panel1.Handle, panel2.Handle);
panel2.Controls.Add(panel1);
panel1.Width = 50;
panel1.Height = 50;
}
private void panel1_MouseDoubleClick(object sender, MouseEventArgs e)
{
SetParent(panel1.Handle, panel2.Handle);
panel2.Controls.Add(panel1);
panel1.Width = 50;
panel1.Height = 50;
}
源代码下载:http://download.csdn.net/source/3439634
如有其它更好方式,请告知,谢谢。