日期:2014-05-18  浏览次数:20892 次

如何去掉Form的标题栏,且保留系统菜单
RT

------解决方案--------------------
用创建不规则窗体的办法把标题栏截掉.
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
Point[] p1 ={ new Point(3, 15), new Point(766, 15), new Point(766, 209), new Point(3, 209), new Point(3, 15) };
GraphicsPath shape = new GraphicsPath();
shape.AddLines(p1);
this.Region = new Region(shape);
}

这样的话假定的窗体大小是(766,209),标题栏占用宽15;
你试一下,是可以的.
要添加引用
using System.Drawing.Drawing2D;
using System.Drawing;

------解决方案--------------------
//api declear
[DllImport("user32.dll", EntryPoint="SetWindowLong")]
public static extern int SetWindowLong (
int hwnd,
int nIndex,
int dwNewLong
);

[DllImport("user32.dll", EntryPoint="GetWindowLong")]
public static extern int GetWindowLong (
int hwnd,
int nIndex
);

public const int GWL_STYLE = (-16);
public const int WS_SYSMENU = 0x80000;

//实现代码
public static void AddSystemMenuToForm(IntPtr WindowHandle)
{
int oldStyle = GetWindowLong(WindowHandle.ToInt32(),GWL_STYLE);
SetWindowLong(WindowHandle.ToInt32(),GWL_STYLE,oldStyle|WS_SYSMENU);
}

//调用
AddSystemMenuToForm(this);