Sunday 8 November 2009

C# Re-enable Borderless Form Startbar Menu and Minimize behaviour

HOW TO:
Re-enable the default Start bar right-click Menu and default left-click minimize and maximize behaviour for a windows borderless form.

Add this anywhere to the code of the form:

C#

protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
//cp.Style |= 0x80000; // Turn on WS_SYSMENU - just SYSMENU
cp.Style |= 0xA0000; // Turn on WS_SYSMENU and Minimize !!!
return cp;
}
}

According to developerfusion.com/tools/convert/csharp-to-vb below is the equivalent VB, although I haven't tested that yet.

Protected Overloads Overrides ReadOnly Property CreateParams() As CreateParams
Get
Dim cp As CreateParams = MyBase.CreateParams
'cp.Style = cp.Style Or &H80000 - Turn on WS_SYSMENU - just SYSMENU
cp.Style = cp.Style Or &Ha0000
' Turn on WS_SYSMENU and Minimize !!!
Return cp
End Get
End Property


Some of my sources for working this out were as follows: (I wrote this up here because nowhere I could find laid it out clearly and straightforwardly... I had to spend a half out go through 10 different docs before I hit on the above and discovered it worked.)

dotnetrix

windowsdevelop

bytes.com

itags - this appears to be a copy of a b-board discussion, but it does not provide a link back to the original discussion. It refers to links and stuff inside the discussion which are not there... which didn't help, however it did give me another number to try out!

No comments: