Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 990
  • Last Modified:

Programmatically click the minimize button in VB.NET

I wrote a .NET app that I would like to minimize programmatically without using me.windowstate.  

Here's the issue -- when I click on a regular button that I made with the code Me.WindowState = Windows.Forms.FormWindowState.Minimized, the form does minimize, but the memory usage does not go down.

However, if I click the standard minimize button in the upper right hand corner of the form, the form minimizes and the memory usage plummets, which is what I'm looking for. (Even though the memory usage figure might only be cosmetic).

My question -- does anyone know how to programmatically simulate clicking the little minimize button at the top right of the form?
0
jacksonm1234
Asked:
jacksonm1234
2 Solutions
 
GuitarRichCommented:
I would imagine that the memory goes down when you click the minimize button as the program then looses focus and is minimized. But when you set your form windowstate the program still has the focus.
After you've clicked on your button to minimize the form, try selecting a different program that is already open and see if the memory usage changes.
0
 
CodeCruiserCommented:
You can using the windows message loop to send a minimize message to the window.
This link might be helpful.
http://www.thescarms.com/vbasic/ShowWindow.aspx

Also
http://ryanfarley.com/blog/archive/2004/05/10/605.aspx

0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Haven't looked at the code in the project linked by CodeCruiser  but I suspect it's using this method?
Public Class Form1
 
    Private Const SW_MINIMIZE As Integer = 6
    Private Declare Function ShowWindow Lib "user32" Alias "ShowWindow" (ByVal handle As IntPtr, ByVal nCmdShow As Integer) As Integer
 
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        ShowWindow(Me.Handle, SW_MINIMIZE)
    End Sub
 
End Class

Open in new window

0

Featured Post

NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now