Form from external DLL does not Show after being minimized - vb.net

This is probably behavior by design, but I'll ask anyway -
I call a form from another project dll in my main project. It is NOT Modal (ShowDialog) or TopMost, and I set a variable for the form once it's created ("frm = New ..."), so that I can check when it's already been created (user clicks a toolbar button to create it initially.)
The form displays, fires events etc. all perfectly.
However, if I MINIMIZE the form and then call frm.Show through code to bring it back, nothing happens. The form remains minimized.
frm.Show has no affect and doesn't seem to fire any other events.
The only way to bring it back is to click on the taskbar icon for the MAIN form, which then displays the MAIN form AND the minimized forms (as icons), and then click on the icon for the minimized form.
I've tried various events (.Activate, .Show, .ShowDialog, .Focus) NOTHING will bring the other form out of its minimized state other than physically clicking on the Taskbar MAIN app icon and then selecting it.
Also, the main application is not MDI...
???
Thanks.

normally this should do it as suggested by #jimi
[TheForm].WindowState = FormWindowState.Normal
But sometimes this does not works for some dark reason, so you could use some other methods
form.Show();
form.BringToFront();
if (form.WindowState == FormWindowState.Minimized)
{
ShowWindowAsync(form.Handle, 9); // 9 = SW_RESTORE
}
I am sure there is one of these that will fix your problem

Related

vb.net - Multiple dialog forms push Main form behind other apps

We have a VB.Net Application with a Main form that should always be visible. However, we want to be able to display a succession of two dialog windows where we can close the first dialog as the second one appears. However, when doing that, the Main form gets sent behind whatever other applications are open and does not re-appear until the second dialog window closes.
We can correct this issue by keeping the first dialog window open behind the second one, but it’s not ideal. What are we doing incorrectly?
Try using dialog1.owner = mainform

vb.net - how to keep my main app in focus on desktop?

I have an application that is created using windows forms in VB. In my application, I have a button that opens up another (child) form. When that (child) form is closed, my other form (main app form) takes the focus, the only problem is that if I have other applications open on my desktop, when my child form closes, the main parent form goes to the back of my desktop for a second and then comes back to the top. So basically when you close the child form, even if the main form is on top of all of the other apps on the desktop, it will be thrown to the back momentarily and another app will be shown and then my VB app will come back to the top. It lasts for about one second and then comes back on its own, I don't have to do anything to bring it back to the top. It is very annoying. Is there any way to prevent this?
Thanks.
Yes. Set the topmost property of the form to true e.g. Form1.TopMost = True. In the closing function of the childforms, set this property of your main form. As the form closes the main form should set this property to false and then use Form/Me.Focus or Form/Me.BringToFront command if you like.

Opening winforms in the same screen

I have an application with multiple win forms. I have noticed is that if the user has multiple screen displays and changes the application to one screen, the other forms that are called by other buttons, will open in the main display and not where my main application or form is.
How can I change this?
You can use the Form.CenterToParent Method on your Forms, they will then open up centered on your the creating Form, Or you can use the Screen Class to get the Bounds of the Display that your Main application is running on, then pass it to your created forms.
Edit:
On second thought assigning the Owner might just be enough, I don't have a dual monitor computer booted up at this time to test though
Dim frm As Form1 = New Form1()
frm.Owner = Me
frm.CenterToParent()
frm.Show()
Edit
Just had a chance to check it out. It was as I thought assigning the Owner to the new Form or using the Form.Show(IWin32Window) will open the new Form on the same screen as the originating Form.
frm.Show(Me)
Looks like the CenterToParent property is protected now.
According to the MSDN link
Do not call the CenterToParent method directly from your code. Instead, set the StartPosition property to CenterParent.
If the form or dialog is top-level, then CenterToParent centers the form with respect to the screen or desktop

OOB NewForm in Dialog loses focus after a few seconds

Working in SharePoint 2010, with SharePoint Designer 2010, I have a DispForm to which I've added a DVWP that displays a filtered view of another relative list. The DVWP has a 'New' link which opens the NewForm for that list in a modal dialog, using OpenPopUpPage (http://msdn.microsoft.com/en-us/library/ff410825.aspx).
After 5 - 12 seconds, the blinking cursor disappears from the first control and the focus switches to the 'Close' button. If the user was trying to type and happens to hit the Enter key when the focus switches to the 'Close' button, the background is no longer darkened and the 'Cancel' button no longer works. The form is still displayed on the screen, and the user can 'Save' but the modal never goes away until the page is refreshed.
If the user notices that the modal has lost focus and clicked back on the form, everything works as it should and all is well.
Observations:
When the control/modal loses focus, the 'Close' button does not trigger a 'focusin' event. But, $(document.activeElement).attr("value") displayed in the console shows that it's the active element.
Questions:
Why is the modal losing focus?
Does anyone have a Javascript/jQuery workaround to capture the event and set the focus back where it was?
Alternately, what if I lock the form and wait for this focus-change to complete, then unlock it and set the focus on the first field? Ideas?
You may be having a problem if the DispForm is also a dialog and you open the modal with your script. It sounds like you are getting a "layered" effect. My guess is that the script managing the dialog is interfering with the modal. Have you tried turning off the dialiogs for the list?
Just so I get some points on this site, the affliction was the asynchronous refresh of the first modal. It was taking the focus away from the layered modal.
Thanks JB for the answer!
I figured out the problem: the DVWP was using Auto-Refresh with the Async Update. This was running every 15 secs, taking the focus away from the modal, then not returning it to the last control.
So, we turned of the auto-refresh and used the callback from the modal close to trigger a click on the manual refresh button instead.

Modal Dialog with secondary form shown in taskbar

I have two forms for my application, that are visible in the Windows taskbar. When a modal dialog is popped up on the main form, the secondary form is locked. However, when the user clicks on the secondary form on the taskbar, it appears over the modal dialog box, and is basically frozen.
Is there a way to ensure that the modal dialog box does not draw underneath the secondary form? The topmost property is no good, since this draws on top of everything, even stuff not related to the application.
Your problem may be that you haven't specified an owner for the dialog:
Owned windows typically don’t need their own representation on the Windows taskbar because they are subordinate to their owners. Because activating an owned window implicitly activates the owner and vice versa, it would merely clutter up the taskbar to have entries for both. So owned forms normally have their ShowInTaskBar properties set to false.
The following code fragments (in VB and C#) show a new form being created, owned, and displayed:
// defining an owner form in C#
MyForm ownedForm = new MyForm();
ownedForm.ShowInTaskbar = false;
AddOwnedForm(ownedForm);
ownedForm.Show();
In your case, it would appear that you need to set the owner window for the dialog. That would prevent the window that is presenting the dialog from appearing over it.
EDIT Should have cited my source: .NET Windows Forms in a Nutshell. Also, I omitted the VB.NET code. I have appropriately flogged myself, but don't feel like wading through the PDF file to track it down.