1

Closed

Minimize/Normalize form with ribbon

description

Minimizing and then normalizing a Windows Form with the Ribbon, cause the Form to expand every time. Additional - minimizing the form and setting "showintaskbar" = false, destroys the framework and "hides" the ribbon.
Closed Jan 10, 2011 at 6:30 PM by arik
Check out the following discussion for a fix:http://windowsribbon.codeplex.com/Thread/View.aspx?ThreadId=240773

comments

rasmusfoged wrote Nov 14, 2010 at 4:44 PM

Issue found. The ShowInTaskbar property on a Windows Form, makes the form re-create its handle upon ShowInTaskbar = True. Only option to solve this is to re-use Win32 API.

arik wrote Nov 16, 2010 at 6:06 PM

So is the issue solved? or did you just understand the problem?
Also, what do you mean by "re-use Win32 API"?

rasmusfoged wrote Nov 16, 2010 at 10:14 PM

Issues is solved with the work-around to use Win32 API for hiding the form in taskbar. See VB.NET code below:

<code>
Imports System.Runtime.InteropServices

Public Class NativeMethods
<DllImport("user32.dll")> _
Private Shared Function SetWindowLong(ByVal hWnd As IntPtr, ByVal nIndex As Integer, ByVal dwNewLong As Integer) As Integer
End Function
<DllImport("user32.dll")> _
Private Shared Function GetWindowLong(ByVal hWnd As IntPtr, ByVal nIndex As Integer) As Integer
End Function
<DllImport("user32.dll", SetLastError:=True)> _
Private Shared Function ShowWindow(ByVal hWnd As IntPtr, ByVal nCmdShow As Integer) As Boolean
End Function

Private Const WS_EX_APPWINDOW As Integer = &H40000
Private Const GWL_EXSTYLE As Integer = -20
Private Const WS_EX_TOOLWINDOW As Integer = &H80
Private Const SW_HIDE As Integer = 0
Private Const SW_SHOW As Integer = 5

Friend Shared Sub ShowInTaskbar(ByVal form As Form, ByVal show As Boolean)
    If show = False Then
        ShowWindow(form.Handle, SW_HIDE)
        SetWindowLong(form.Handle, GWL_EXSTYLE, GetWindowLong(form.Handle, GWL_EXSTYLE) And (Not WS_EX_APPWINDOW))
    Else
        ShowWindow(form.Handle, SW_SHOW)
    End If
End Sub
End Class
</code>

rasmusfoged wrote Nov 16, 2010 at 10:14 PM

Issues is solved with the work-around to use Win32 API for hiding the form in taskbar. See VB.NET code below:

<code>
Imports System.Runtime.InteropServices

Public Class NativeMethods
<DllImport("user32.dll")> _
Private Shared Function SetWindowLong(ByVal hWnd As IntPtr, ByVal nIndex As Integer, ByVal dwNewLong As Integer) As Integer
End Function
<DllImport("user32.dll")> _
Private Shared Function GetWindowLong(ByVal hWnd As IntPtr, ByVal nIndex As Integer) As Integer
End Function
<DllImport("user32.dll", SetLastError:=True)> _
Private Shared Function ShowWindow(ByVal hWnd As IntPtr, ByVal nCmdShow As Integer) As Boolean
End Function

Private Const WS_EX_APPWINDOW As Integer = &H40000
Private Const GWL_EXSTYLE As Integer = -20
Private Const WS_EX_TOOLWINDOW As Integer = &H80
Private Const SW_HIDE As Integer = 0
Private Const SW_SHOW As Integer = 5

Friend Shared Sub ShowInTaskbar(ByVal form As Form, ByVal show As Boolean)
    If show = False Then
        ShowWindow(form.Handle, SW_HIDE)
        SetWindowLong(form.Handle, GWL_EXSTYLE, GetWindowLong(form.Handle, GWL_EXSTYLE) And (Not WS_EX_APPWINDOW))
    Else
        ShowWindow(form.Handle, SW_SHOW)
    End If
End Sub
End Class
</code>

rasmusfoged wrote Nov 16, 2010 at 10:14 PM

Issues is solved with the work-around to use Win32 API for hiding the form in taskbar. See VB.NET code below:

Imports System.Runtime.InteropServices

Public Class NativeMethods
<DllImport("user32.dll")> _
Private Shared Function SetWindowLong(ByVal hWnd As IntPtr, ByVal nIndex As Integer, ByVal dwNewLong As Integer) As Integer
End Function
<DllImport("user32.dll")> _
Private Shared Function GetWindowLong(ByVal hWnd As IntPtr, ByVal nIndex As Integer) As Integer
End Function
<DllImport("user32.dll", SetLastError:=True)> _
Private Shared Function ShowWindow(ByVal hWnd As IntPtr, ByVal nCmdShow As Integer) As Boolean
End Function

Private Const WS_EX_APPWINDOW As Integer = &H40000
Private Const GWL_EXSTYLE As Integer = -20
Private Const WS_EX_TOOLWINDOW As Integer = &H80
Private Const SW_HIDE As Integer = 0
Private Const SW_SHOW As Integer = 5

Friend Shared Sub ShowInTaskbar(ByVal form As Form, ByVal show As Boolean)
    If show = False Then
        ShowWindow(form.Handle, SW_HIDE)
        SetWindowLong(form.Handle, GWL_EXSTYLE, GetWindowLong(form.Handle, GWL_EXSTYLE) And (Not WS_EX_APPWINDOW))
    Else
        ShowWindow(form.Handle, SW_SHOW)
    End If
End Sub
End Class

arik wrote Jan 10, 2011 at 6:27 PM

Check out the following discussion for a fix:
http://windowsribbon.codeplex.com/Thread/View.aspx?ThreadId=240773

wrote Jan 10, 2011 at 6:30 PM

wrote Feb 22, 2013 at 12:15 AM

wrote May 16, 2013 at 11:57 AM