Solved

Programmatically click the minimize button in VB.NET

Posted on 2009-07-16
3
970 Views
Last Modified: 2012-05-07
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
Comment
Question by:jacksonm1234
3 Comments
 
LVL 12

Expert Comment

by:GuitarRich
ID: 24869965
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
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 250 total points
ID: 24870461
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
 
LVL 85

Assisted Solution

by:Mike Tomlinson
Mike Tomlinson earned 250 total points
ID: 24948270
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question