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.
Related
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
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
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
I am using VB.NET to build my application. And in my application has a lot of Forms. It doesn't use MDI Parent Form, but I use another simple Window Form (I named it frmMain) that I suppose it is my MDI Parent Form. When frmMain load, windowState = Maximized. And when I open a Form (example: I named it frmCustomer) that I suppose it is my child Form, and I set its properties (frmCustomer.TopMost=True) when it load, so it always on the top. But When I change to open another application such as Ms. Word or Mozilla Firefox... the frmCustomer is still on the top. My question is that; how can I know my frmMain lost focus?
If you want the form to stay in front of the main form, but not other applications, the simpler solution would be to set the main form as the child form's owner. For instance:
childForm.Show(parentForm)
or
childForm.Owner = parentForm
Just finishing off an update to an application written in VB.NET that used to run fine under CE.NET 4.2. Deployment platform is now Windows Mobile 6.1.
The application runs in full screen, however whenever a new form is opened, the task bar, i.e. the bar with the start button comes to the fore and then the new form takes over. This is particularly annoying as I have a form that has many sub forms which are 128,128 and still the task bar flashes and obscures part of the user input screen.
Has anyone comes across this? Any known workarounds?
You can use the technique I posted here to disable the task bar.
I assume your application flow is something like:
Form 1 open.
Form 1 close.
Form 2 open.
The problem is that between the Form 1 closing and the Form 2 opening the background window may be partially drawn (e.g. the task bar will draw).
To work around this we normally create a parent window (which is your case is full-screen window) which sits behind the form windows. That way when one is closing and the next is opening it falls back to displaying the parent window which can display anything you like (blank?).