Can't get a form to show in front of another - vb.net

On my main form I call
WaitingForm.Show()
WaitingForm.Focus()
WaitingForm.Select()
and then run work in a backgroundworker. For some reason that form never opens in front of my main form though. How can I get it to show infront?

I assume you have instantialized this New Form if it was created programatically. In which case you can use the Topmost Property of the Form.
Hope that helps.

Use the Form.Owner property to make a form owned by another form. Assign its Owner property a reference to the form that will be the owner. For example:
WaitingForm.Show(Me)

Related

Run a method from form 1 to run in form 2 vb.net

I have two forms. Form one (mainForm) has a listview with a method called on loading the form to populate the list (private sub populateUsers) with users from a database . This works perfectly. I have a button on the form that opens a second form while keeping the first form open (required for the program) to add new users (newUserForm). When the user is saved to the database via a button in the new user form, this form is hidden. The problem is trying to call the method from form one via a button in form two to repopulate the list and add the new user.
I have searched for an answer but no luck. Any ideas?
Thanks
P.S. I have tried assigning form 1 to a variable in form 2 but this doesn't work. I have tried to directly use the method when pressing the button but no luck. I have tested it with a messagebox function so form 2 is able to use methods from form 1.
Use this one :
Public Sub '.......................... (Name of your event like on_click)
My.Forms.Form2.MethodName 'Replace method name with your method name
End Sub

Reset usercontrol placed on form

Probably simple question but couldn't find any working solution. I have User control on windows form. I would like on button click placed on user control to reload user control. By reload i mean to reset all its variables and show again. How to achieve that?
There is nothing that does that. You could dispose the existing control and create a new one but noone would do that. Basically, it's a manual process. If you want the control's fields reset to defaults then you need to write code to do that. You might declare a Reset method and put all the code in there if that's appropriate and then you can simply call that method from the form.

Making multiple forms appear as one in VB.NET

I am writing a Windows Forms application in VB.NET. I have three forms: the main form, which shows a list of accounts, the account form which allows the user to view/edit the information for a specific account, and the policy form which allows the user to view/edit the information on a specific policy for that account. I want the forms to appear as if they are all the same window. Example: when the application starts, the user clicks an account name in the list box on the main form and clicks "edit". What I want to happen is that the window stays in the exact same place and stays the same exact size, only the content of the main form appears to be replaced with the content of the account form. Same thing if the user then chooses to edit a policy from the account form. When the user finishes and clicks "save", the main form comes back up. Through this entire use case, it would appear to the user as if they were viewing the same window the entire time, with the content of that window changing.
How can I do this? I have tried something like:
Dim newForm as New AcctForm
newForm.Location = Me.Location
newForm.Show()
Me.Close()
The problem is that if the user moves the original window, the new window appears where the parent form originally appeared, not where it ended up.
I see this is already in the comments, but what I have done in this case in the past is build each "form" in the application as a custom control. Then I have one actual form, and navigation works by changing which custom control is currently loaded on the parent form. To move from one screen/view to another, you remove the current custom control from the form's controls collection and add the new custom control.
I believe this is superior to manually setting the startup position and size, because you can use the form's .SuspendLayout()/.ResumeLayout() methods to hide the interim state, where there is no control loaded, from the user. This is harder to do when you want one form to be completely replaced by another.
This also makes it easy to set certain form properties in one place and have them be consistent for the application. You can even have an area on the form with controls that will now show in every view.
When using this pattern, I typically have each of my custom controls inherit from a common base. You may not have anything specific you will do with that base at the outset, but it almost always comes in handy later.
Finally, switching to use this scheme is easier than you think. Just go to the code for the each of your current forms, and you will find that each class currently inherits from System.Windows.Forms.Form. Most of the time, all you really need to do is change them to inherit from System.Windows.Forms.Panel and you're most of the way there.
As others have said, it may be better to redesign your application using custom controls or panels etc.
However, to answer your question regarding the seemingly random location of your forms, the first thing to check is that each form has it's StartPosition property set to Manual.
If your main form is resizable, then I would also add code to adjust newForm to the same size too.
I hope that helps with your immediate issues; so that you can move on to redesigning the application!
good morning there is another way . set property for second form to (top most) and use also
from2.show();
that make you switch between forms and keep form2 top other
Thanks
try using ShowDialog()
Dim newForm as New AcctForm
newForm.Location = Me.Location
newForm.ShowDialog()
Me.Close() <-- removed this

Hide main form initially...Possible? (VB language)

Is there a way to start a Windows Forms in (VB language) application with the main window not visible? Then later on when an external event occurs, I want to display the form.
How can I accomplish this?
Thanks.
Hint: See the 'Visible' property.
Initially you just put:
Load SuperAmazingForm
..then when you want to display the form, simply call its Show method as normal.
Doing it this way allows you to interact with the form's objects without the user being aware of it.
It depends on if you are doing this in Excel/Word or Access. If you are using Excel/Word then the Load MyForm syntax works. However, Access uses it's own variation of the standard UserForm. To load a form hidden you can do:DoCmd.OpenForm "MyAccessForm", WindowMode:=acHidden.

Hiding columns in a datasheet

I am trying to hide specific columns in an Access 2007 split form through code. I need the form to check certain conditions to see whether it needs to display a column or not. I have code in the form's 'Activate' event to hide the column like this:
txtControl.ColumnHidden = True
This code works in the "Open" event, but if I hide the column on Activate, it won't display these changes until I close the form and open it again. I have tried calling the form's refresh, repaint, and requery methods, but this doesn't work. Please help!
Edit: Ideally, I need this event to occur whenever the focus switches to this form.That's why I'm using the Activate event rather than the Open event.
Try setting it in either the form's Current or Load events. You will also probably need to requery the control after setting that property: Me.TextControl.Requery Current is called every time a form's record is changed, the form is repainted or requeried. Load, as its name suggests, is called once, after the form has opened when the form loads its records. These have always been more reliable for me than using Activate, which really has to do with more the focus of the form, not really what you want.
I've had a problem like this before working in Access 2002. I was able to solve the problem with a subform by setting the subform source object equal to itself and then running the requery.
Me.SubForm.SourceObject = Me.SubForm.SourceObject
Me.SubForm.Requery
See if this technique works for your particular situation.