Resolved setting ShowInTaskbar=False disables the Form_Resize event... how to detect resize?

gicalle

New member
Joined
Dec 4, 2013
Messages
4
Programming Experience
10+
Hello,
this is a normal resize event. It's triggered as expected on a normal form.

VB.NET:
Private Sub Form1_Resize(sender As System.Object, e As System.EventArgs) Handles MyBase.Resize
        WriteInfoMessage("resize")
End Sub


the resize event is no longer triggered as soon as ShowInTaskbar is set to False.
VB.NET:
Me.ShowInTaskbar = False


why? and how can i detect a resizing or detect hiding of this form?
 
Last edited:
I can't reproduce the problem you describe, ShowInTaskbar=False and Resize event work fine. I also could not find anybody else on the internet having that problem. So it must be something else you're or your Windows system is doing, or a combination with some other setting you have.
Check for yourself that is not something else by starting with a new project, only change ShowInTaskbar for the form, add Resize event handler and debug output/stop, then start it.
 
Sorry, you're right. To be more specific, the resize event is not triggered when showing the desktop! (by using windows+d e.g. or by clicking on the 'show desktop' icon in windows).
before ShowInTaskbar it's ok, after ShowInTaskbar = false it's no longer triggered.

And I want to have my form always visible (but no TopMost), thus restoring to Normal windowstate as soon as it is 'hidden' by the desktop.


so the problem is that the resize event is no longer triggered by showing the desktop as soon as icon is removed from taskbar...
 
thanks.

solution:
declare
VB.NET:
   [DllImport("user32.dll")]
   static extern IntPtr GetShellWindow();

   [DllImport("user32.dll", SetLastError = true)]
   static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);

and then call to bind your own form to the 'desktop' window (and thus showing up when displaying the desktop).
VB.NET:
SetParent(this.Handle, GetShellWindow());
 
Ok, except that is C# code, and this is a VB.Net forum.
 
vb code:

VB.NET:
Imports System.Runtime.InteropServices


Public Class Form1
    Declare Function GetShellWindow Lib "user32.dll" () As IntPtr


    <DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
    Public Shared Function SetParent(ByVal hWndChild As IntPtr, ByVal hWndNewParent As IntPtr) As IntPtr
    End Function


    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        SetParent(Me.Handle, GetShellWindow())
    End Sub
End Class
 
Back
Top