Solved

Programmatically click the minimize button in VB.NET

Posted on 2009-07-16
3
974 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

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

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

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

739 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