Solved

Programmatically click the minimize button in VB.NET

Posted on 2009-07-16
3
977 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 86

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

The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

734 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