catch minimization

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • iwdu15

    #1

    catch minimization

    hi, how can i catch when the user clicks the minimize button on the form and
    do a certain event then? what im looking to do is when the user minimizes the
    form, to put the form on the system tray. i kno how to put it on the tray but
    how do i catch when its been minimized? thanks
    --
    -iwdu15
  • jdm

    #2
    Re: catch minimization

    =?Utf-8?B?aXdkdTE1?= <iwdu15@discuss ions.microsoft. com> wrote in
    news:B3374D3F-A458-413F-B25E-876843247474@mi crosoft.com:
    [color=blue]
    > hi, how can i catch when the user clicks the minimize button on the
    > form and do a certain event then? what im looking to do is when the
    > user minimizes the form, to put the form on the system tray. i kno how
    > to put it on the tray but how do i catch when its been minimized?
    > thanks[/color]

    there's an example here


    :

    Protected Overrides Sub WndProc(ByRef m As _
    System.Windows. Forms.Message)
    Const WM_SYSCOMMAND As Long = &H112
    Const SC_MINIMIZE As Long = &HF020&
    Const SC_MAXIMIZE As Long = &HF030&
    ' See if this is WM_SYSCOMMAND.
    If m.Msg = WM_SYSCOMMAND Then
    ' Ignore SC_MINIMIZE and SC_MAXIMIZE commands.
    If (m.WParam.ToInt 32 And &HFFF0&) = SC_MINIMIZE Then
    MsgBox("Can't Minimize!!")
    Exit Sub
    End If
    If (m.WParam.ToInt 32 And &HFFF0&) = SC_MAXIMIZE Then
    MsgBox("Can't Maximize!!")
    Exit Sub
    End If
    End If
    MyBase.WndProc( m)
    End Sub

    Comment

    • iwdu15

      #3
      Re: catch minimization

      awsome thanks

      Comment

      • Herfried K. Wagner [MVP]

        #4
        Re: catch minimization

        "jdm" <null@invalid.c om> schrieb:[color=blue]
        > Protected Overrides Sub WndProc(ByRef m As _
        > System.Windows. Forms.Message)
        > Const WM_SYSCOMMAND As Long = &H112
        > Const SC_MINIMIZE As Long = &HF020&
        > Const SC_MAXIMIZE As Long = &HF030&[/color]

        Note that 'Long' is a 64-bit datatype in VB.NET. Thus you'll have to change
        the longs to ints:

        \\\
        Private Const WM_SYSCOMMAND As Int32 = &H112

        Private Const SC_MAXIMIZE As Int32 = &HF030
        Private Const SC_MINIMIZE As Int32 = &HF020
        Private Const SC_RESTORE As Int32 = &HF120
        Private Const SC_CLOSE As Int32 = &HF060

        Protected Overrides Sub WndProc(ByRef m As Message)
        If m.Msg = WM_SYSCOMMAND Then
        Select Case m.WParam.ToInt3 2()
        Case SC_MAXIMIZE
        Debug.WriteLine ("Form gets maximized.")
        Case SC_MINIMIZE
        Debug.WriteLine ("Form gets minimized.")
        Case SC_RESTORE
        Debug.WriteLine ("Form gets restored.")
        Case SC_CLOSE
        Debug.WriteLine ("Form gets closed.")
        End Select
        End If
        MyBase.WndProc( m)
        End Sub
        ///

        --
        M S Herfried K. Wagner
        M V P <URL:http://dotnet.mvps.org/>
        V B <URL:http://classicvb.org/petition/>

        Comment

        • Jay B. Harlow [MVP - Outlook]

          #5
          Re: catch minimization

          iwdu15,
          In addition to the other comments.

          I normally simply handle the Resize event.

          Something like:

          Protected Overrides Sub OnResize(ByVal e As System.EventArg s)
          MyBase.OnResize (e)
          Select Case Me.WindowState
          Case FormWindowState .Normal
          MessageBox.Show ("Form was restored",
          Application.Pro ductName)
          Case FormWindowState .Minimized
          MessageBox.Show ("Form was minimized",
          Application.Pro ductName)
          Case FormWindowState .Maximized
          MessageBox.Show ("Form was maximized",
          Application.Pro ductName)
          End Select
          End Sub


          --
          Hope this helps
          Jay [MVP - Outlook]
          T.S. Bradley - http://www.tsbradley.net


          "iwdu15" <iwdu15@discuss ions.microsoft. com> wrote in message
          news:B3374D3F-A458-413F-B25E-876843247474@mi crosoft.com...
          | hi, how can i catch when the user clicks the minimize button on the form
          and
          | do a certain event then? what im looking to do is when the user minimizes
          the
          | form, to put the form on the system tray. i kno how to put it on the tray
          but
          | how do i catch when its been minimized? thanks
          | --
          | -iwdu15


          Comment

          Working...