I think the easiest way to archive this is to hide the standard controlbox and make your own controlbox made of buttons,and replicate the original controlbox funcionality.
Edit:
As per CHill60 request,i'm improving this a little bit. There are two ways to archive this i think. One is just doing something like this:
this.ControlBox = false;
this.FormBorderStyle = FormBorderStyle.None;
And then use a label and three buttons ,put them on top of the form and replicate the close,maximize and restore funcionality.
This is visually not ideal, as you loose the aero glass effect,you can't resize the form and some other disadvantages, but for many things it just do the job.
The other one involves using dwmapi,extending the frame into the client area and then removing the standard frame. This is a lot more advanced, but if you are interested in it i'll try to find some time to make a working example.
Edit 2
Well, this is the other way to do this. You can improve it a lot,but you'll get the idea with this. It's a bit long, so there we go:
public partial class Form1 : Form
{
[DllImport("dwmapi.dll", CharSet = CharSet.Auto, PreserveSig = false,
SetLastError = true)]
internal static extern void DwmIsCompositionEnabled(out bool pfEnable);
[DllImport("dwmapi.dll", CharSet = CharSet.Auto, PreserveSig = false,
SetLastError = true)]
internal static extern void DwmExtendFrameIntoClientArea(
IntPtr hWnd,
[In] ref MARGINS margins);
[DllImport("dwmapi.dll", CharSet = CharSet.Auto, PreserveSig = false,
SetLastError = true)]
internal static extern void DwmEnableBlurBehindWindow(IntPtr hWnd,
DWM_BLURBEHIND pBlurBehind);
private Region marginRegion = null;
public MARGINS GlassMargins { get; set; }
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct MARGINS
{
public int cxLeftWidth;
public int cxRightWidth;
public int cyTopHeight;
public int cyBottomHeight;
public MARGINS(int margin)
{
cxLeftWidth = margin;
cxRightWidth = margin;
cyTopHeight = margin;
cyBottomHeight = margin;
}
public MARGINS(int leftWidth, int rightWidth,
int topHeight, int bottomHeight)
{
cxLeftWidth = leftWidth;
cxRightWidth = rightWidth;
cyTopHeight = topHeight;
cyBottomHeight = bottomHeight;
}
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
internal class DWM_BLURBEHIND
{
public uint dwFlags;
[MarshalAs(UnmanagedType.Bool)]
public bool fEnable;
public IntPtr hRegionBlur;
[MarshalAs(UnmanagedType.Bool)]
public bool fTransitionOnMaximized;
public const uint DWM_BB_ENABLE = 0x00000001;
public const uint DWM_BB_BLURREGION = 0x00000002;
public const uint DWM_BB_TRANSITIONONMAXIMIZED = 0x00000004;
}
static Color transparentColor = Color.DarkTurquoise;
public Form1()
{
InitializeComponent();
this.GlassMargins = new MARGINS(3, 3, 30, 3);
this.ControlBox = false;
this.FormBorderStyle = FormBorderStyle.Sizable;
this.TransparencyKey = transparentColor;
this.AllowTransparency = true;
Button b = new Button();
b.Location = new Point(this.Width - 27, 3);
b.Size = new Size(24, 24);
b.Text = "X";
b.BackColor = Color.Red;
b.Click += new EventHandler(b_Click);
this.Controls.Add(b);
Label lab = new Label();
lab.Text = "Aero Glass custom Form";
lab.Location = new Point(3, 9);
lab.AutoSize = true;
lab.BackColor = Color.Transparent;
this.Controls.Add(lab);
}
void b_Click(object sender, EventArgs e)
{
this.Close();
}
protected override void OnSizeChanged(EventArgs e)
{
base.OnSizeChanged(e);
this.Invalidate();
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
using (Brush transparentBrush = new SolidBrush(transparentColor))
{
var glassMargins = this.GlassMargins;
DwmExtendFrameIntoClientArea(this.Handle,
ref glassMargins);
marginRegion = new Region(this.ClientRectangle);
marginRegion.Exclude(new Rectangle(
this.GlassMargins.cxLeftWidth,
this.GlassMargins.cyTopHeight,
this.ClientSize.Width - this.GlassMargins.cxLeftWidth - this.GlassMargins.cxRightWidth,
this.ClientSize.Height - this.GlassMargins.cyTopHeight - this.GlassMargins.cyBottomHeight));
e.Graphics.FillRegion(transparentBrush, marginRegion);
}
}
protected override void WndProc(ref Message message)
{
const Int32 WM_NCHITTEST = 0x84;
const Int32 WM_NCCALCSIZE = 0x0083;
switch (message.Msg)
{
case WM_NCHITTEST:
ProcessHitTest(ref message);
break;
case WM_NCCALCSIZE:
if (isDwmWindowFramePaintEnabled() && message.WParam != IntPtr.Zero)
{
message.Result = IntPtr.Zero;
}
else
{
base.WndProc(ref message);
}
break;
default:
base.WndProc(ref message);
break;
}
}
void ProcessHitTest(ref Message m)
{
Point p = this.PointToClient(
new Point(m.LParam.ToInt32()));
m.Result = (IntPtr)(p.Y < 30 ?
UnmanagedMethods.HitTestReturnType.Caption
: UnmanagedMethods.HitTestReturnType.Client);
}
private bool isDwmWindowFramePaintEnabled()
{
bool result;
try
{
DwmIsCompositionEnabled(out result);
return result;
}
catch (DllNotFoundException)
{
return false;
}
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (this.marginRegion != null)
{
marginRegion.Dispose();
}
}
}