为什么是WS_EX_TOOLWINDOW,见CreateWindowExMSDN参考。 public partial class Form1 : Form { public Form1() { InitializeComponent(); this.FormBorderStyle = FormBorderStyle.None; } protected override CreateParams CreateParams { get { const int WS_EX_APPWINDOW = 0x00040000; const int WS_EX_TOOLWINDOW = 0x00000080; CreateParams result = base.CreateParams; result.ExStyle = result.ExStyle & (~WS_EX_APPWINDOW); result.ExStyle = result.ExStyle | WS_EX_TOOLWINDOW; return result; } } }
修改创建窗口参数的ExStyle样式 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms;namespace WindowsApplication126 { public partial class Form1 : Form { public Form1() { InitializeComponent(); this.FormBorderStyle = FormBorderStyle.None; this.ShowInTaskbar = false; } protected override CreateParams CreateParams { get { int WS_EX_TOOLWINDOW = 0x80; CreateParams CP=base.CreateParams; CP.ExStyle= CP.ExStyle|WS_EX_TOOLWINDOW; return CP; } } } }
但是我必须要用FormBorderStyle.None,而且还不能Hide()
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.FormBorderStyle = FormBorderStyle.None;
} protected override CreateParams CreateParams
{
get
{
const int WS_EX_APPWINDOW = 0x00040000;
const int WS_EX_TOOLWINDOW = 0x00000080; CreateParams result = base.CreateParams;
result.ExStyle = result.ExStyle & (~WS_EX_APPWINDOW);
result.ExStyle = result.ExStyle | WS_EX_TOOLWINDOW;
return result;
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace WindowsApplication126
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent(); this.FormBorderStyle = FormBorderStyle.None;
this.ShowInTaskbar = false;
} protected override CreateParams CreateParams
{
get
{
int WS_EX_TOOLWINDOW = 0x80;
CreateParams CP=base.CreateParams; CP.ExStyle= CP.ExStyle|WS_EX_TOOLWINDOW;
return CP;
}
}
}
}
protected override void SetVisibleCore(bool values)
{
base.SetVisibleCore(values);
}然后在Load的时候调用SetVisibleCore
{
get
{
int WS_EX_TOOLWINDOW = 0x80;
CreateParams CP = base.CreateParams; CP.ExStyle = CP.ExStyle | WS_EX_TOOLWINDOW;
return CP;
}
} protected override CreateParams CreateParams
{
get
{
const int WS_EX_APPWINDOW = 0x00040000;
const int WS_EX_TOOLWINDOW = 0x00000080; CreateParams result = base.CreateParams;
result.ExStyle = result.ExStyle & (~WS_EX_APPWINDOW);
result.ExStyle = result.ExStyle | WS_EX_TOOLWINDOW;
return result;
}
}