Open form minimized

A

Armin Zingler

Hi again,

in the designer, I set windowstate = minimized, but when I start the app -
the form is the startup object - the form is first shown in restored state,
then minimized immediatelly. How can I prevent it from being shown in
restored state first?

Another problem: In it's resize event, I hide the form (there's a NotifyIcon
to make it visible again). When it gets minimized at startup, the resize
event is raised and "me.visible=false" is executed correctly, but it's still
visible in the taskbar. What can I do?

Armin
 
A

Adrian Matei

Hi!
You could use P/Invoke to send WM_SYSCOMMAND message.
For instance, declare

[System.Runtime.InteropServices.DllImport("user32.dll",
EntryPoint="SendMessage")]
public static extern void SendMessage(IntPtr hWnd, int Message, int wParam,
int lParam);

and register your form to Load event. Inside that method, insert
SendMessage(this.Handle, 0x0112, 61472, 0);

Hope that helps!
Best regards, Adrian
 
A

Armin Zingler

Adrian Matei said:
Hi!
You could use P/Invoke to send WM_SYSCOMMAND message.
For instance, declare

[System.Runtime.InteropServices.DllImport("user32.dll",
EntryPoint="SendMessage")]
public static extern void SendMessage(IntPtr hWnd, int Message, int
wParam, int lParam);

and register your form to Load event. Inside that method, insert
SendMessage(this.Handle, 0x0112, 61472, 0);

Hope that helps!
Best regards, Adrian


No, it didn't help, despite thanks for your answer. The only thing that
changes is that the correct form size defined in the designer isn't used
anymore. Which of the two problems mentioned should be solved by this? Even
if it worked, the question remains, why setting WindowState=Minimized in the
designer isn't sufficient to show the form minimized at startup.


Further research revealed the real cause of the problem:
The first resize event occurs before the form is made visible, exactly in
InitializeComponent at the line setting the ClientSize property. At that
point, the Form is still invisible, but as the Windowstate is still not
minimized - because the Windowstate property will be set later in
Initializecomponent - the Form is made visible (that's what I do in the
resize event), and that's still the restored state. Later, while executing
Initializecomponent, the windowstate is set to minimized.

The solution is not to respond to the resize event but to WM_SIZE in WndProc
instead. Works perfectly.

Armin
 
N

news.microsoft.com

Armin,

Both setting WindowsState in the designer and hiding the form work perfectly
for me. I guess you have some other code that causes that undesired effect.

Probably you should post some compilable code that demonstrates the problem.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top